feat: enable diarization by default with an opt-out

Request speaker diarization through OpenRouter's Azure provider options for
all transcription uploads. Add --no-diarization to explicitly disable it for
both plain text and SRT output; returned speaker labels let existing SRT
cue generation split at speaker changes.

Default to 10-minute chunks when diarization is enabled because Microsoft
reports failures around 15 minutes and longer. Preserve the 30-minute
default with the opt-out and honor explicit --chunk-minutes values in both
modes. Document the options, duration limits, and output behavior.

Test Plan:
- python3 -B -m unittest -v: all 32 tests passed, including request options,
  default upload limits, opt-out combinations, and SRT speaker boundaries.
- bash -n transcribe: passed.
- ./transcribe --help: verified the new option and chunk defaults.
- git diff --cached --check: passed.
- Provider responses were mocked; no live API request was made.
This commit is contained in:
ddidderr committed 2026-09-12 09:04:29 +02:00
1 parent a5c535cfb9
commit 24b1030776
4 files changed
+121 -10

No files matched your search

+13 -4
View File
@@ -3,16 +3,19 @@
set -euo pipefail
srt=false
chunk_minutes=30
diarization=true
chunk_minutes=
usage() {
echo "Usage: ${0##*/} [--srt] [--chunk-minutes 1..30] AUDIO_FILE"
echo "Usage: ${0##*/} [--srt] [--no-diarization] [--chunk-minutes 1..30] AUDIO_FILE"
echo 'Transcribe audio using OPENROUTER_API_KEY; print the text to stdout.'
echo ' --srt Print SRT subtitles in short cues using word timestamps instead.'
echo ' --chunk-minutes N Maximum upload duration in minutes (default: 30).'
echo ' --no-diarization Disable speaker diarization (enabled by default).'
echo ' --chunk-minutes N Maximum upload duration in minutes (default: 10; 30 with --no-diarization).'
}
while [[ $# -gt 0 ]]; do
case $1 in
--srt) srt=true; shift ;;
--no-diarization) diarization=false; shift ;;
--chunk-minutes)
if [[ ! ${2:-} =~ ^([1-9]|[12][0-9]|30)$ ]]; then
echo '--chunk-minutes must be an integer between 1 and 30' >&2
@@ -27,6 +30,10 @@ while [[ $# -gt 0 ]]; do
*) break ;;
esac
done
if [[ -z $chunk_minutes ]]; then
# Azure documents diarization failures for recordings around 15 minutes.
if "$diarization"; then chunk_minutes=10; else chunk_minutes=30; fi
fi
if [[ $# != 1 ]]; then
usage >&2
exit 1
@@ -76,7 +83,9 @@ for ((i = 0; i < count; i++)); do
# Keep large audio payloads out of shell arguments (which have a size limit).
base64 <"$tmp/audio.mp3" | tr -d '\n\r' >"$tmp/audio.b64"
jq -n --rawfile data "$tmp/audio.b64" --argjson timestamps "$timestamps" \
'{model: "microsoft/mai-transcribe-2", input_audio: {data: $data, format: "mp3"}}
--argjson diarization "$diarization" \
'{model: "microsoft/mai-transcribe-2", input_audio: {data: $data, format: "mp3"},
provider: {options: {azure: {diarization: {enabled: $diarization}}}}}
+ (if $timestamps then {response_format: "verbose_json", timestamp_granularities: ["segment", "word"]}
else {} end)' \
>"$tmp/request.json"