Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix(device-ts): contain Whisper transcript callback errors
  • Loading branch information
1aifanatic committed Oct 3, 2026
commit bafd1f8aa6ded78e2bb84d6a7fa1bc870966d7c9
23 changes: 23 additions & 0 deletions sdks/device/typescript/src/stt/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,29 @@ describe('createWhisperTranscriber', () => {

expect(transcripts).toEqual(['final transcript']);
});

test('contains first and final callback errors while delivering the next batch', async () => {
const attempted: string[] = [];
const transcripts: string[] = [];
let calls = 0;
const transcriber = createWhisperTranscriber({
runner: () => ['first', 'second', 'tail'][calls++]!,
onTranscript: (text) => {
attempted.push(text);
if (text !== 'second') throw new Error('synthetic callback failure');
transcripts.push(text);
},
batchSeconds: 1,
});
transcriber.appendPcm(new Uint8Array(32000));
transcriber.appendPcm(new Uint8Array(32000));
transcriber.appendPcm(new Uint8Array([1, 0]));
transcriber.stop();
await new Promise((resolve) => setImmediate(resolve));

expect(attempted).toEqual(['first', 'second', 'tail']);
expect(transcripts).toEqual(['second']);
});
});

describe('parakeetWsUrl', () => {
Expand Down
5 changes: 2 additions & 3 deletions sdks/device/typescript/src/stt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ export function createWhisperTranscriber(opts: {
const pcm = buffer;
buffer = new Uint8Array(0);
const job = async () => {
let text = '';
try {
text = await opts.runner(pcm);
const text = await opts.runner(pcm);
if (text) opts.onTranscript(text);
} catch {
return;
}
if (text) opts.onTranscript(text);
};
queue = queue.then(job, job);
}
Expand Down
Loading