mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-09-16 05:16:21 -07:00
- Detect PATH tools and report missing executable settings - Check output directories before model downloads or audio extraction
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { runSubtitleGenerationProcess } from './subtitle-generation-process';
|
|
|
|
// Each completed silencedetect line contains both the end and duration of a quiet interval.
|
|
export async function findSpeechPauses(input: {
|
|
ffmpegPath: string;
|
|
wavPath: string;
|
|
signal?: AbortSignal;
|
|
}): Promise<number[]> {
|
|
const pauses: number[] = [];
|
|
await runSubtitleGenerationProcess({
|
|
command: input.ffmpegPath,
|
|
args: [
|
|
'-nostdin',
|
|
'-hide_banner',
|
|
'-nostats',
|
|
'-i',
|
|
input.wavPath,
|
|
'-af',
|
|
'silencedetect=noise=-35dB:d=0.12',
|
|
'-f',
|
|
'null',
|
|
'-',
|
|
],
|
|
signal: input.signal,
|
|
onLine: (line) => {
|
|
const match = /silence_end: (\S+) \| silence_duration: (\S+)/.exec(line);
|
|
if (!match) return;
|
|
const end = Number(match[1]);
|
|
const duration = Number(match[2]);
|
|
if (Number.isFinite(end) && Number.isFinite(duration) && duration > 0 && end >= duration)
|
|
pauses.push(end - duration / 2);
|
|
},
|
|
});
|
|
return pauses.sort((a, b) => a - b);
|
|
}
|