fix(cli): check hears a WAV whose header misstates its byte rate, as render plays it (#7618)

* fix(cli): check hears a WAV whose header misstates its byte rate, as render plays it

A PCM WAV whose header byte rate is wrong (some speech generators write 2x) sent the silence decode's input seek past the file's end, so every clip past the middle was reported audio_clip_silent. Render already cuts such a file by decoded time (#7541); the byte-rate rule now lives in parsers and the CLI decoder seeks after decoding starts for those files.

* test(cli): keep the misstated byte-rate case with the other single-clip checks

* style(cli): format the WAV test helper

* style(parsers): keep the byte-rate rule's comment within the line limit
This commit is contained in:
Miguel Ángel
2026-11-12 19:30:02 +00:00
committed by GitHub
parent 5bf361f524
commit 97df93fb07
5 changed files with 45 additions and 21 deletions
+14 -3
View File
@@ -11,8 +11,13 @@ const RATE = 48_000;
const dir = mkdtempSync(join(tmpdir(), "hf-check-audio-"));
afterAll(() => rmSync(dir, { recursive: true, force: true }));
/** A mono 16-bit WAV of `seconds`, each sample from `fill`. */
function wav(name: string, seconds: number, fill: (t: number) => number): string {
/** A mono 16-bit WAV of `seconds`, each sample from `fill`; `byteRate` is the header's claim. */
function wav(
name: string,
seconds: number,
fill: (t: number) => number,
byteRate = RATE * 2,
): string {
const frames = Math.round(seconds * RATE);
const data = Buffer.alloc(frames * 2);
for (let i = 0; i < frames; i++) data.writeInt16LE(Math.round(fill(i / RATE) * 32767), i * 2);
@@ -24,7 +29,7 @@ function wav(name: string, seconds: number, fill: (t: number) => number): string
header.writeUInt16LE(1, 20);
header.writeUInt16LE(1, 22);
header.writeUInt32LE(RATE, 24);
header.writeUInt32LE(RATE * 2, 28);
header.writeUInt32LE(byteRate, 28);
header.writeUInt16LE(2, 32);
header.writeUInt16LE(16, 34);
header.write("data", 36);
@@ -72,6 +77,8 @@ describe.skipIf(!ffmpeg)("inspectAudio", () => {
// Long enough to be sampled at spots first; sound only between the spots.
wav("long-silent.wav", 20, silent);
wav("long-gap.wav", 20, (t) => (t > 5 && t < 6 ? tone(t) : 0));
// Its header claims twice the real byte rate, as some speech generators write it.
wav("misstated-rate.wav", 8, tone, RATE * 4);
// Not audio at all: the render's audio probe rejects it and the whole mix fails.
writeFileSync(join(dir, "notes.wav"), "RIFF but not really a wave file");
// A 1x1 PNG: it probes, but as a still image, so render refuses it as an <audio> source.
@@ -176,6 +183,10 @@ describe.skipIf(!ffmpeg)("inspectAudio", () => {
// Played at double speed, 2 s of film reach 4 s into the file, past the silent start.
expect(await codes(media([clip("late.wav", { end: 2, playbackRate: 2 })]))).toEqual([]);
});
it("hears a clip past the middle of a WAV whose header misstates its byte rate, as render plays it", async () => {
expect(await codes(media([clip("misstated-rate.wav", { mediaStart: 5 })]))).toEqual([]);
});
});
describe("inspectAudio on a project of many clips trimmed from few files", () => {
+1
View File
@@ -67,6 +67,7 @@ async function silentPart(
sampleRate: probed.sampleRate,
channels: probed.channels,
duration: probed.durationSeconds,
misstatedByteRate: probed.misstatedByteRate,
},
{ mono: true, sampleRate: SILENCE_SAMPLE_RATE },
);