Skip to content

Commit 24a09a2

Browse files
committed
fix(cli): transcribe audio with no speech as 0 words instead of failing
Parakeet writes an empty word list for a music bed, a silent intro or a very short clip, and loading it failed with "Unrecognized JSON transcript format". An empty list is now read as a transcript with no words, as whisper's empty output already is. A non-empty list still has to look like words.
1 parent 1bee3a1 commit 24a09a2

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎packages/cli/src/whisper/normalize.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ describe("detectFormat", () => {
8484
});
8585

8686
describe("loadTranscript", () => {
87+
it("reads an empty word list as a transcript with no words", () => {
88+
expect(loadTranscript(tmpFile("transcript.json", "[]"))).toEqual({
89+
words: [],
90+
format: "words-json",
91+
});
92+
});
93+
94+
it("still rejects a JSON array that is not a word list", () => {
95+
expect(() => loadTranscript(tmpFile("transcript.json", '[{"foo":1}]'))).toThrow(
96+
/Unrecognized JSON transcript format/,
97+
);
98+
});
99+
87100
it("parses whisper-cpp JSON with punctuation merging", () => {
88101
const path = tmpFile(
89102
"transcript.json",

‎packages/cli/src/whisper/normalize.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ function detectJsonFormat(raw: unknown): TranscriptFormat {
4848
if (obj.transcription && Array.isArray(obj.transcription)) return "whisper-cpp";
4949
if (obj.words && Array.isArray(obj.words)) return "openai";
5050
}
51-
if (Array.isArray(raw) && raw[0]?.text !== undefined && raw[0]?.start !== undefined) {
51+
if (
52+
Array.isArray(raw) &&
53+
raw.slice(0, 1).every((w) => w?.text !== undefined && w?.start !== undefined)
54+
) {
5255
return "words-json";
5356
}
5457
throw new Error(

0 commit comments

Comments
 (0)