#!/usr/bin/env node // Sortformer diarization engine for scripts/diarize.mjs. // // The exact counterpart of scripts/diarize-sherpa.py, and deliberately the same // shape: decode audio, run the model, print raw turns as JSON on stdout. All // policy (filenames, provenance shape, atomic writes) lives in the .mjs wrapper. // // stdout is JSON ONLY. Progress goes to stderr so the wrapper can stream it. // // WHAT THIS ADDS OVER THE BINARY: audio decoding. scripts/sortformer/ // diarize-file.cpp only speaks 16 kHz mono PCM, and the corpus holds mp3, m4a, // webm and whole video containers. ffmpeg does that here, exactly as the sherpa // engine shells out to ffmpeg for the same reason. // // NO TEMPORARY WAV, ON PURPOSE. A decoded 8-hour VOD is ~900 MB, this box's disk // runs at 98%, and /tmp is frequently a tmpfs — writing one would be the largest // single risk in this lane. ffmpeg's raw output is piped straight into the // engine, which consumes it in blocks, so neither process ever holds the file. // // Usage (invoked by diarize.mjs; runnable directly for debugging): // diarize-sortformer.mjs --bin --model [options]