From 0013da8ed5fdcf36dd3148db4bfb1a20ef26605e Mon Sep 17 00:00:00 2001 From: sudacode Date: Sat, 28 Nov 2026 04:46:40 -0800 Subject: [PATCH] fix(subsync): keep single-pass Silero fallback out of the Silero cache key --- src/subsync/audio-speech.test.ts | 47 ++++++++++++++++++++++++++++++++ src/subsync/audio-speech.ts | 6 +++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/subsync/audio-speech.test.ts b/src/subsync/audio-speech.test.ts index 914ce114..bea96b2f 100644 --- a/src/subsync/audio-speech.test.ts +++ b/src/subsync/audio-speech.test.ts @@ -297,3 +297,50 @@ exit 0 fs.rmSync(tmpDir, { recursive: true, force: true }); } }); + +test('the single pass does not cache a built-in fallback under the Silero key', async () => { + if (process.platform === 'win32') return; + clearAudioSpeechCache(); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-single-pass-vad-')); + try { + const videoPath = path.join(tmpDir, 'episode.mkv'); + const modelPath = path.join(tmpDir, 'silero.bin'); + const ffmpegScript = path.join(tmpDir, 'ffmpeg.sh'); + const vadScript = path.join(tmpDir, 'whisper-vad.sh'); + fs.writeFileSync(videoPath, 'video'); + fs.writeFileSync(modelPath, 'model'); + // Writes a tiny WAV for the single pass and silence for the built-in PCM fallback. + fs.writeFileSync( + ffmpegScript, + `#!/bin/sh +last="" +for arg in "$@"; do + case "$arg" in + *.wav) printf 'RIFF....WAVEdata................................................' > "$arg" ;; + esac + last="$arg" +done +if [ "$last" = "pipe:1" ]; then dd if=/dev/zero bs=1600 count=1 2>/dev/null; fi +exit 0 +`, + { mode: 0o755 }, + ); + fs.writeFileSync(vadScript, '#!/bin/sh\nexit 1\n', { mode: 0o755 }); + const vadPaths = { vadExecutablePath: vadScript, vadModelPath: modelPath }; + + const rip = await extractSinglePassRipMedia({ + ffmpegPath: ffmpegScript, + videoPath, + audioStreamIndex: 1, + ...vadPaths, + embeddedTracks: [], + includeAudio: true, + }); + + assert.equal(rip?.audioSpeech?.source, 'builtin-vad'); + assert.equal(getCachedAudioSpeechSpans(videoPath, 1, vadPaths), null); + } finally { + clearAudioSpeechCache(); + fs.rmSync(tmpDir, { recursive: true, force: true }); + } +}); diff --git a/src/subsync/audio-speech.ts b/src/subsync/audio-speech.ts index 67cd8f16..34cc58e0 100644 --- a/src/subsync/audio-speech.ts +++ b/src/subsync/audio-speech.ts @@ -907,7 +907,11 @@ export async function extractSinglePassRipMedia( } } - if (audioSpeech) { + // audioKey names the configured detector. A built-in fallback after a Silero failure was + // already cached under the built-in key by extractAudioSpeechSpans; storing it here too + // would make later runs skip Silero. + const matchesConfiguredDetector = !useSilero || audioSpeech?.source === 'silero-vad'; + if (audioSpeech && matchesConfiguredDetector) { rememberAudioSpeech(audioKey, audioSpeech); } }