Skip to content

Commit 6d7e9bd

Browse files
authored
79 audio property is incorrect when using save audio append to current multiple recordings (#96)
* First pass at fixing the appending of audio * Move audio file saving higher up in the call chain logic in updateFrontMatter calls * Setup frontmatter immediately after finishing a recording. Better error handling * Update frontmatter handling to preserve audio references during recording process * Bumps version to 2.2.9
1 parent 6c45593 commit 6d7e9bd

File tree

5 files changed

+78
-38
lines changed

5 files changed

+78
-38
lines changed

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ Always includes a `fileTitle` field for note renaming.
173173
1. User clicks "Complete" → `plugin.scribe(scribeOptions)`
174174
2. `audioRecord.stopRecording()` → Blob → ArrayBuffer
175175
3. `saveAudioRecording()` → audio file in vault
176-
4. Create/get target note (new note or append to active file)
177-
5. Setup frontmatter (`audio: [[path]]`, `created_by: [[Scribe]]`)
176+
4. Create/get target note (new note or append to active file) via `resolveTargetNote`
177+
5. Update frontmatter immediately via `updateFrontMatter` (append `audio` list + `created_by`) so audio reference is preserved even if downstream stages fail
178178
6. Transcribe via OpenAI or AssemblyAI → transcript text
179179
7. Replace "# Audio in progress" placeholder with transcript
180180
8. (If not transcribe-only) Summarize via LLM → structured JSON

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "scribe",
33
"name": "Scribe",
4-
"version": "2.2.8",
4+
"version": "2.2.9",
55
"minAppVersion": "0.15.0",
66
"description": "Record, transcribe, and transform voice notes into structured insights. Leverage Whisper or AssemblyAI and ChatGPT to fill in gaps, generate summaries, and visualize ideas — all seamlessly integrated within Obsidian.",
77
"author": "Mike Alicea",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-scribe-plugin",
3-
"version": "2.2.8",
3+
"version": "2.2.9",
44
"description": "An Obsidian plugin for recording voice notes, transcribing the audio, and summarizing the text - All in one",
55
"main": "build/main.js",
66
"scripts": {

src/index.ts

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
createNewNote,
2121
renameFile,
2222
saveAudioRecording,
23-
setupFileFrontmatter,
23+
updateFrontMatter,
2424
} from './util/fileUtils';
2525
import {
2626
mimeTypeToFileExtension,
@@ -169,7 +169,19 @@ export default class ScribePlugin extends Plugin {
169169
const { recordingBuffer, recordingFile } =
170170
await this.handleStopAndSaveRecording(baseFileName);
171171

172+
const note = await this.resolveTargetNote(
173+
baseFileName,
174+
scribeOptions.isAppendToActiveFile,
175+
);
176+
177+
if (scribeOptions.isSaveAudioFileActive) {
178+
await updateFrontMatter(this, note, recordingFile);
179+
} else {
180+
await updateFrontMatter(this, note);
181+
}
182+
172183
await this.handleScribeFile({
184+
note,
173185
audioRecordingFile: recordingFile,
174186
audioRecordingBuffer: recordingBuffer,
175187
scribeOptions: scribeOptions,
@@ -212,10 +224,26 @@ export default class ScribePlugin extends Plugin {
212224
new Notice('Scribe: ⚠️ This file type is not supported.');
213225
return;
214226
}
227+
const baseFileName = formatFilenamePrefix(
228+
this.settings.recordingFilenamePrefix,
229+
this.settings.dateFilenameFormat,
230+
);
215231

216232
const audioFileBuffer = await this.app.vault.readBinary(audioFile);
217233

234+
const note = await this.resolveTargetNote(
235+
baseFileName,
236+
scribeOptions.isAppendToActiveFile,
237+
);
238+
239+
if (scribeOptions.isSaveAudioFileActive) {
240+
await updateFrontMatter(this, note, audioFile);
241+
} else {
242+
await updateFrontMatter(this, note);
243+
}
244+
218245
await this.handleScribeFile({
246+
note,
219247
audioRecordingFile: audioFile,
220248
audioRecordingBuffer: audioFileBuffer,
221249
scribeOptions: scribeOptions,
@@ -290,11 +318,32 @@ export default class ScribePlugin extends Plugin {
290318
return { recordingBuffer, recordingFile };
291319
}
292320

321+
private async resolveTargetNote(
322+
baseFileName: string,
323+
isAppendToActiveFile: boolean,
324+
): Promise<TFile> {
325+
let note = isAppendToActiveFile
326+
? (this.app.workspace.getActiveFile() as TFile)
327+
: await createNewNote(this, baseFileName);
328+
329+
if (!note) {
330+
new Notice('Scribe: ⚠️ No active file to append to, creating new one!');
331+
note = (await createNewNote(this, baseFileName)) as TFile;
332+
333+
const currentPath = this.app.workspace.getActiveFile()?.path ?? '';
334+
this.app.workspace.openLinkText(note.path, currentPath, true);
335+
}
336+
337+
return note;
338+
}
339+
293340
async handleScribeFile({
341+
note,
294342
audioRecordingFile,
295343
audioRecordingBuffer,
296344
scribeOptions,
297345
}: {
346+
note: TFile;
298347
audioRecordingFile: TFile;
299348
audioRecordingBuffer: ArrayBuffer;
300349
scribeOptions: ScribeOptions;
@@ -305,28 +354,6 @@ export default class ScribePlugin extends Plugin {
305354
isSaveAudioFileActive,
306355
activeNoteTemplate,
307356
} = scribeOptions;
308-
const scribeNoteFilename = `${formatFilenamePrefix(
309-
this.settings.noteFilenamePrefix,
310-
this.settings.dateFilenameFormat,
311-
)}`;
312-
313-
let note = isAppendToActiveFile
314-
? (this.app.workspace.getActiveFile() as TFile)
315-
: await createNewNote(this, scribeNoteFilename);
316-
317-
if (!note) {
318-
new Notice('Scribe: ⚠️ No active file to append to, creating new one!');
319-
note = (await createNewNote(this, scribeNoteFilename)) as TFile;
320-
321-
const currentPath = this.app.workspace.getActiveFile()?.path ?? '';
322-
this.app.workspace.openLinkText(note?.path, currentPath, true);
323-
}
324-
325-
if (isSaveAudioFileActive) {
326-
await setupFileFrontmatter(this, note, audioRecordingFile);
327-
} else {
328-
await setupFileFrontmatter(this, note);
329-
}
330357

331358
await this.cleanup();
332359

src/util/fileUtils.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,43 @@ export async function renameFile(
100100
);
101101
}
102102

103-
export async function setupFileFrontmatter(
103+
function normalizeAudioFrontmatterValues(audio: unknown): string[] {
104+
if (Array.isArray(audio)) {
105+
return audio.filter(
106+
(value): value is string => typeof value === 'string' && value.length > 0,
107+
);
108+
}
109+
110+
if (typeof audio === 'string' && audio.length > 0) {
111+
return [audio];
112+
}
113+
114+
return [];
115+
}
116+
117+
export async function updateFrontMatter(
104118
plugin: ScribePlugin,
105119
noteFile: TFile,
106120
audioFile?: TFile,
107121
) {
108122
try {
109123
await plugin.app.fileManager.processFrontMatter(noteFile, (frontMatter) => {
110-
const newFrontMatter = {
111-
...frontMatter,
112-
audio: audioFile
113-
? [...(frontMatter.source || []), `[[${audioFile.path}]]`]
114-
: frontMatter.source,
115-
};
124+
const existingAudio = normalizeAudioFrontmatterValues(frontMatter.audio);
116125

117-
if (plugin.settings.isFrontMatterLinkToScribe) {
118-
newFrontMatter.created_by = '[[Scribe]]';
126+
if (audioFile) {
127+
frontMatter.audio = [...existingAudio, `[[${audioFile.path}]]`];
128+
} else if (frontMatter.audio !== undefined) {
129+
frontMatter.audio = existingAudio;
119130
}
120131

121-
Object.assign(frontMatter, newFrontMatter);
132+
if (plugin.settings.isFrontMatterLinkToScribe) {
133+
frontMatter.created_by = '[[Scribe]]';
134+
}
122135
});
123136

124137
return noteFile;
125138
} catch (error) {
126-
console.error('Failed to addAudioSourceToFrontmatter', error);
139+
console.error('Failed to update frontmatter', error);
127140
throw error;
128141
}
129142
}

0 commit comments

Comments
 (0)