Skip to content

Commit ee41acf

Browse files
committed
fix(tts-local-cli): normalize all Ogg output
Treat Ogg only as a source container and always transcode it to the requested target, so malformed or ambiguous Ogg bytes can never bypass conversion as native voice audio.
1 parent 0d64118 commit ee41acf

2 files changed

Lines changed: 11 additions & 37 deletions

File tree

‎extensions/tts-local-cli/speech-provider.test.ts‎

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -328,38 +328,21 @@ describe("buildCliSpeechProvider", () => {
328328
}
329329
});
330330

331-
it("keeps Ogg Opus native for voice-note targets", async () => {
332-
const audio = createOggFirstPage(Buffer.from("OpusHeadnative-audio"));
333-
const fixture = createRawAudioFixture([...audio]);
334-
try {
335-
const result = await synthesize({
336-
providerConfig: baseProviderConfig(fixture.script, {
337-
args: [fixture.script, "--text", "{{Text}}"],
338-
outputFormat: "opus",
339-
}),
340-
target: "voice-note",
341-
});
342-
343-
expect(result).toEqual({
344-
audioBuffer: audio,
345-
outputFormat: "opus",
346-
fileExtension: ".ogg",
347-
voiceCompatible: true,
348-
});
349-
expect(runFfmpegMock).not.toHaveBeenCalled();
350-
} finally {
351-
rmSync(fixture.dir, { recursive: true, force: true });
352-
}
353-
});
354-
355331
it.each([
356-
{ transport: "stdout", outputArgs: [] },
357332
{
333+
codec: "OpusHead",
334+
packet: Buffer.from("OpusHeadnative-audio"),
335+
transport: "stdout",
336+
outputArgs: [],
337+
},
338+
{
339+
codec: "Vorbis",
340+
packet: Buffer.from("\x01vorbis-not-OpusHead"),
358341
transport: "templated file",
359342
outputArgs: ["--out", "{{OutputDir}}/{{OutputBase}}.ogg"],
360343
},
361-
])("converts Ogg Vorbis from $transport to Opus for voice notes", async (testCase) => {
362-
const audio = createOggFirstPage(Buffer.from("\x01vorbis-not-OpusHead"));
344+
])("converts Ogg $codec from $transport to Opus for voice notes", async (testCase) => {
345+
const audio = createOggFirstPage(testCase.packet);
363346
const fixture = createRawAudioFixture([...audio]);
364347
try {
365348
const result = await synthesize({

‎extensions/tts-local-cli/speech-provider.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,7 @@ function detectAudioFormat(buffer: Buffer): SourceFormat | null {
189189
if (hasMpegFrameHeader(buffer, 0) || (prefix.startsWith("ID3") && hasId3v2MpegFrame(buffer))) {
190190
return "mp3";
191191
}
192-
if (!prefix.startsWith("OggS")) {
193-
return null;
194-
}
195-
const segmentCount = buffer[26] ?? 0;
196-
const firstSegmentLength = buffer[27] ?? 0;
197-
const firstPacketOffset = 27 + segmentCount;
198-
const firstPacketPrefix = buffer.toString("ascii", firstPacketOffset, firstPacketOffset + 8);
199-
return segmentCount > 0 && firstSegmentLength >= 8 && firstPacketPrefix === "OpusHead"
200-
? "opus"
201-
: "ogg";
192+
return prefix.startsWith("OggS") ? "ogg" : null;
202193
}
203194

204195
function getFileExt(format: SourceFormat): string {

0 commit comments

Comments
 (0)