From 9a39f00f94f4ea2141b3f3e022d703e9875939e4 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 11 Jul 2026 18:36:24 -0400 Subject: [PATCH] Diarization fix --- src/audio.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/audio.ts b/src/audio.ts index 8efdb97..cb591e5 100644 --- a/src/audio.ts +++ b/src/audio.ts @@ -141,11 +141,18 @@ print(json.dumps(segments)) if(!llm) return transcript; let chunks = this.ai.language.chunk(transcript, 500, 0); if(chunks.length > 4) chunks = [...chunks.slice(0, 3), chunks.at(-1)]; - const names = await this.ai.language.json(chunks.join('\n'), '{1: "Detected Name", 2: "Second Name"}', { - system: 'Use the following transcript to identify speakers. Only identify speakers you are positive about, dont mention speakers you are unsure about in your response', + await this.ai.language.ask(chunks.join('\n'), { + system: 'Read the following transcript and attempt to identify every speaker. For every positively identified speaker, call the \`identify\` tool with the speaker\'s ID number & the identified name exactly once.', temperature: 0.1, + tools: [ + {name: 'identify', description: 'Identify a speaker', args: { + speaker: {type: 'number', description: 'Speaker number', required: true}, + name: {type: 'string', description: 'Inferred name', required: true}, + }, fn: ({speaker, name}) => { + transcript = transcript.replaceAll(`[Speaker ${speaker}]`, `[${name}]`); + }} + ] }); - Object.entries(names).forEach(([speaker, name]) => transcript = transcript.replaceAll(`[Speaker ${speaker}]`, `[${name}]`)); return transcript; }