Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 feature request turn off summary - only transcribe #7

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "scribe",
"name": "Scribe",
"version": "1.0.4",
"version": "1.0.5",
"minAppVersion": "0.15.0",
"description": "Record voice notes, Fill in lost thoughts, Transcribe the audio, Summarize & Visualize the text - All in one clip",
"author": "Mike Alicea",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-scribe-plugin",
"version": "1.0.4",
"version": "1.0.5",
"description": "An Obsidian plugin for recording voice notes, transcribing the audio, and summarizing the text - All in one",
"main": "build/main.js",
"scripts": {
Expand Down
20 changes: 15 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const DEFAULT_STATE: ScribeState = {
openAiClient: null,
};

export interface ScribeOptions {
isAppendToActiveFile?: boolean;
isOnlyTranscribeActive?: boolean;
}

export default class ScribePlugin extends Plugin {
settings: ScribePluginSettings = DEFAULT_SETTINGS;
state: ScribeState = DEFAULT_STATE;
Expand Down Expand Up @@ -121,7 +126,7 @@ export default class ScribePlugin extends Plugin {
}
}

async scribe(isAppendToActiveFile?: boolean) {
async scribe(scribeOptions: ScribeOptions = {}) {
try {
const baseFileName = createBaseFileName();

Expand All @@ -132,7 +137,7 @@ export default class ScribePlugin extends Plugin {
baseNoteAndAudioFileName: baseFileName,
audioRecordingFile: recordingFile,
audioRecordingBuffer: recordingBuffer,
isAppendToActiveFile,
scribeOptions: scribeOptions,
});
} catch (error) {
new Notice(`Scribe: Something went wrong ${error.toString()}`);
Expand Down Expand Up @@ -225,13 +230,14 @@ export default class ScribePlugin extends Plugin {
baseNoteAndAudioFileName,
audioRecordingFile,
audioRecordingBuffer,
isAppendToActiveFile,
scribeOptions = {},
}: {
baseNoteAndAudioFileName: string;
audioRecordingFile: TFile;
audioRecordingBuffer: ArrayBuffer;
isAppendToActiveFile?: boolean;
scribeOptions?: ScribeOptions;
}) {
const { isAppendToActiveFile, isOnlyTranscribeActive } = scribeOptions;
const scribeNoteFilename = `scribe-${baseNoteAndAudioFileName}`;

let note = isAppendToActiveFile
Expand All @@ -254,7 +260,11 @@ export default class ScribePlugin extends Plugin {
this.app.workspace.openLinkText(note?.path, currentPath, true);

const transcript = await this.handleTranscription(audioRecordingBuffer);
await addTranscriptToNote(this, note, transcript);
await addTranscriptToNote(this, note, transcript, isOnlyTranscribeActive);

if (isOnlyTranscribeActive) {
return;
}

const llmSummary = await this.handleTranscriptSummary(transcript);
await addSummaryToNote(this, note, llmSummary);
Expand Down
36 changes: 29 additions & 7 deletions src/modal/components/ModalRecordingOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import type { ScribeOptions } from 'src';

export function ModalRecordingOptions({
isAppendToActiveFile,
setIsAppendToActiveFile,
options,
setOptions,
}: {
isAppendToActiveFile: boolean;
setIsAppendToActiveFile: (value: boolean) => void;
options: ScribeOptions;
setOptions: React.Dispatch<ScribeOptions>;
}) {
const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setIsAppendToActiveFile(event.target.checked);
const handleChangeIsAppendToActiveFile = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
// setIsAppendToActiveFile(event.target.checked);
setOptions({ ...options, isAppendToActiveFile: event.target.checked });
};
const handleChangeIsOnlyTranscribeActive = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
setOptions({ ...options, isOnlyTranscribeActive: event.target.checked });
// setIsOnlyTranscribeActive(event.target.checked);
};

const { isAppendToActiveFile, isOnlyTranscribeActive } = options;

return (
<div className="scribe-recording-options">
<label>
<input
type="checkbox"
checked={isAppendToActiveFile}
onChange={handleCheckboxChange}
onChange={handleChangeIsAppendToActiveFile}
/>
Append to active file
</label>

<label>
<input
type="checkbox"
checked={isOnlyTranscribeActive}
onChange={handleChangeIsOnlyTranscribeActive}
/>
Only transcribe recording
</label>
</div>
);
}
14 changes: 10 additions & 4 deletions src/modal/scribeControlsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createRoot, type Root } from 'react-dom/client';
import { Modal } from 'obsidian';
import type ScribePlugin from 'src';
import type { ScribeOptions } from 'src';
import { useState } from 'react';
import { ModalSettings } from './components/ModalSettings';
import { ModalRecordingTimer } from './components/ModalRecordingTimer';
Expand Down Expand Up @@ -53,7 +54,12 @@ const ScribeModal: React.FC<{ plugin: ScribePlugin }> = ({ plugin }) => {
const [recordingStartTimeMs, setRecordingStartTimeMs] = useState<
number | null
>(null);
const [isAppendToActiveFile, setIsAppendToActiveFile] = useState(false);
const [scribeOptions, setScribeOptions] = useState<ScribeOptions>({
isAppendToActiveFile: false,
isOnlyTranscribeActive: false,
});

const { isAppendToActiveFile, isOnlyTranscribeActive } = scribeOptions;

const hasOpenAiApiKey = Boolean(plugin.settings.openAiApiKey);

Expand Down Expand Up @@ -84,7 +90,7 @@ const ScribeModal: React.FC<{ plugin: ScribePlugin }> = ({ plugin }) => {
setIsScribing(true);
setRecordingStartTimeMs(null);
setRecordingState('inactive');
await plugin.scribe(isAppendToActiveFile);
await plugin.scribe({ isAppendToActiveFile, isOnlyTranscribeActive });
setIsPaused(false);
setIsActive(false);
setIsScribing(false);
Expand Down Expand Up @@ -139,8 +145,8 @@ const ScribeModal: React.FC<{ plugin: ScribePlugin }> = ({ plugin }) => {
Settings
</button>
<ModalRecordingOptions
isAppendToActiveFile={isAppendToActiveFile}
setIsAppendToActiveFile={setIsAppendToActiveFile}
options={scribeOptions}
setOptions={setScribeOptions}
/>
</div>

Expand Down
11 changes: 11 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,14 @@ If your plugin does not need CSS, delete this file.
align-items: center;
justify-content: space-between;
}

.scribe-recording-options {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: space-between;

label {
margin-bottom: .5em;
}
}
5 changes: 4 additions & 1 deletion src/util/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ export async function addTranscriptToNote(
plugin: ScribePlugin,
noteFile: TFile,
transcript: string,
isOnlyTranscribeActive?: boolean,
) {
try {
const textToAdd = `${transcript}
const textToAdd = isOnlyTranscribeActive
? `${transcript}`
: `${transcript}
${SUMMARY_IN_PROGRESS_HEADER}`;

await plugin.app.vault.process(noteFile, (data) => {
Expand Down