fix: format text transcripts and show speaker markers
Chunked text output previously joined every word into one line and discarded speaker labels. Add a shared plain-text formatter that wraps lines, breaks paragraphs at speaker changes and pauses, and splits long turns while preserving word order. Display provider speaker IDs with chunk scope where needed, without implying that IDs identify the same person across requests. Request structured output for short diarized recordings too, and warn when speaker labels are missing or incomplete. Keep SRT formatting separate and preserve existing line breaks for short requests without diarization. Test Plan: - python3 -B -m unittest -q: all 43 tests passed. - bash -n transcribe and git diff --cached --check: passed. - Reflowed the existing transcript locally and verified all 15,888 words were preserved; source audio and generated transcripts are not committed. - A live excerpt check was blocked before upload by unavailable 1Password access; actual provider diarization remains unverified.
This commit is contained in:
1 parent
24b1030776
commit
38894c2549
7 files changed
+249
-19
No files matched your search
+10
-2
@@ -7,7 +7,7 @@ diarization=true
|
||||
chunk_minutes=
|
||||
usage() {
|
||||
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 'Transcribe audio using OPENROUTER_API_KEY; print wrapped text with speaker markers to stdout.'
|
||||
echo ' --srt Print SRT subtitles in short cues using word timestamps instead.'
|
||||
echo ' --no-diarization Disable speaker diarization (enabled by default).'
|
||||
echo ' --chunk-minutes N Maximum upload duration in minutes (default: 10; 30 with --no-diarization).'
|
||||
@@ -66,6 +66,7 @@ ffmpeg -nostdin -hide_banner -loglevel error -i "$(realpath -- "$1")" \
|
||||
python3 "$script_dir/chunks.py" plan "$tmp/audio.wav" "$chunk_minutes" >"$tmp/chunks.json"
|
||||
count=$(jq 'length' "$tmp/chunks.json")
|
||||
timestamps=$srt
|
||||
if "$diarization"; then timestamps=true; fi
|
||||
if (( count > 1 )); then
|
||||
timestamps=true
|
||||
echo "Splitting audio into $count overlapping chunks (maximum $chunk_minutes minutes each)." >&2
|
||||
@@ -105,6 +106,13 @@ for ((i = 0; i < count; i++)); do
|
||||
elif (.text | type) == "string" then true
|
||||
else error("Transcription failed: missing text in response") end' \
|
||||
"$tmp/response-$i.json" >/dev/null
|
||||
if "$diarization" && jq -e '.text | test("\\S")' "$tmp/response-$i.json" >/dev/null; then
|
||||
if ! jq -e 'any(.words[]?; .speaker != null)' "$tmp/response-$i.json" >/dev/null; then
|
||||
echo "Warning: chunk $((i + 1))/$count returned no speaker labels despite diarization being enabled." >&2
|
||||
elif jq -e 'any(.words[]?; .speaker == null)' "$tmp/response-$i.json" >/dev/null; then
|
||||
echo "Warning: chunk $((i + 1))/$count returned some words without speaker labels." >&2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Only emit a transcript after every chunk succeeds, including SRT conversion.
|
||||
@@ -115,5 +123,5 @@ if (( count > 1 )); then
|
||||
elif "$srt"; then
|
||||
python3 "$script_dir/subtitles.py" "$tmp/response-0.json"
|
||||
else
|
||||
jq -r .text "$tmp/response-0.json"
|
||||
python3 "$script_dir/transcript.py" "$tmp/response-0.json"
|
||||
fi
|
||||
Reference in new issue
Block a user