#!/usr/bin/env node // Standalone parakeet.cpp transcription with overlapped splitting + stitching. // // parakeet-cli only accepts a single WAV and chokes on very long audio (dr_wav's // data-chunk size is 32-bit, so >4GB PCM overflows and yields an empty // transcript). This script works around both: it slices the source into // OVERLAPPING 16kHz-mono WAV windows (the format parakeet-cli resamples to // internally anyway), transcribes each with `--json --timestamps`, then stitches // the per-window word timestamps back into one transcript. The overlap means a // word clipped at one window boundary is always captured whole by the // neighbouring window; a per-boundary cut point in the middle of each overlap // region decides which window owns each word, so nothing is dropped or doubled. // // Dual-use, by design: // * In the app: common/lib/transcriptionApps.ts registers a `parakeet` app // whose binary IS this script. transcribeOne runs it with cwd == the video // dir and an explicit output path, then renames + normalizes the result. // * On the CLI: run it directly. With no output path it prints JSON to stdout. // // Output is chough-native JSON ({ chunk_data: [{ start_time, end_time, text }] }, // seconds) so it flows through the existing normalizeTranscript("chough-json") // path with zero downstream changes. // // Usage: // parakeet-stitch.mjs --model [options] [outputFile] // // Options (env fallback in parens): // --model parakeet .gguf model (PARAKEET_MODEL) [required] // --cli parakeet-cli binary (PARAKEET_CLI, default "parakeet-cli") // --ffmpeg ffmpeg binary (FFMPEG_BIN, default "ffmpeg") // --ffprobe ffprobe binary (FFPROBE_BIN, default derived from ffmpeg) // --segment window length (PARAKEET_SEGMENT_SEC, default 480) // --overlap window overlap (PARAKEET_OVERLAP_SEC, default 6) // --decoder passed through to parakeet-cli (PARAKEET_DECODER) // --lang passed through to parakeet-cli (PARAKEET_LANG) // --device compute device, exported to parakeet-cli as the // PARAKEET_DEVICE env var (parakeet.cpp has no --device // flag): "cpu", "CUDA0", "Vulkan1", ... (PARAKEET_DEVICE) // // Resumable, yt-dlp style: each window's raw parakeet-cli JSON is written to a // per-audio work dir (".