This commit is contained in:
ddidderr committed 2026-09-12 11:44:00 +02:00
1 parent 3042b7743b
commit ac5aeca44d
1 file changed
+28 -11
+28 -11
View File
@@ -24,8 +24,14 @@ usage() {
}
while [[ $# -gt 0 ]]; do
case $1 in
--srt) srt=true; shift ;;
--no-diarization) diarization=false; shift ;;
--srt)
srt=true
shift
;;
--no-diarization)
diarization=false
shift
;;
--speakers)
if [[ ! ${2:-} =~ ^([1-9]|[1-5][0-9]|6[0-4])$ ]]; then
echo '--speakers must be an integer between 1 and 64' >&2
@@ -66,9 +72,18 @@ while [[ $# -gt 0 ]]; do
chunk_minutes=$2
shift 2
;;
-h|--help) usage; exit 0 ;;
--) shift; break ;;
-*) usage >&2; exit 1 ;;
-h | --help)
usage
exit 0
;;
--)
shift
break
;;
-*)
usage >&2
exit 1
;;
*) break ;;
esac
done
@@ -91,7 +106,7 @@ if [[ ! -f $1 || ! -r $1 ]]; then
echo "Cannot read audio file: $1" >&2
exit 1
fi
if (( BASH_VERSINFO[0] < 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] < 1) )); then
if ((BASH_VERSINFO[0] < 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] < 1))); then
echo 'Bash 5.1 or newer is required for parallel chunk processing.' >&2
exit 1
fi
@@ -103,6 +118,8 @@ for tool in "${dependencies[@]}"; do
}
done
PYANNOTE_API_KEY_REF="op://API Keys/pyannote-api/credential"
# Explicit environment keys also work in headless sessions without 1Password.
# Resolve both credentials before starting any paid requests.
if "$diarization" && [[ -z ${PYANNOTE_API_KEY:-} ]]; then
@@ -177,7 +194,7 @@ save_diagnostic "$tmp/chunks.json" chunks.json
count=$(jq 'length' "$tmp/chunks.json")
timestamps=$srt
if "$diarization"; then timestamps=true; fi
if (( count > 1 )); then
if ((count > 1)); then
timestamps=true
echo "Splitting audio into $count overlapping chunks (maximum $chunk_minutes minutes each)." >&2
echo "Processing up to $jobs chunks in parallel." >&2
@@ -190,7 +207,7 @@ transcribe_chunk() {
mkdir -- "$work"
read -r start duration < <(jq -r --argjson i "$i" \
'.[$i] | "\(.start) \(.end - .start)"' "$tmp/chunks.json")
if (( count > 1 )); then
if ((count > 1)); then
echo "Transcribing chunk $((i + 1))/$count (start ${start}s, duration ${duration}s)..." >&2
fi
ffmpeg -nostdin -hide_banner -loglevel error -y -ss "$start" -i "$tmp/audio.wav" \
@@ -255,8 +272,8 @@ wait_for_worker() {
# response filenames retain recording order regardless of completion order.
set -m
next=0
while (( next < count || ${#workers[@]} > 0 )); do
while (( next < count && ${#workers[@]} < jobs )); do
while ((next < count || ${#workers[@]} > 0)); do
while ((next < count && ${#workers[@]} < jobs)); do
transcribe_chunk "$next" &
workers[$!]=$next
next=$((next + 1))
@@ -270,7 +287,7 @@ while (( next < count || ${#workers[@]} > 0 )); do
fi
done
# Only emit a transcript after every chunk succeeds, including SRT conversion.
if "$diarization" || "$srt" || (( count > 1 )); then
if "$diarization" || "$srt" || ((count > 1)); then
python3 -B "$script_dir/chunks.py" merge "$tmp/chunks.json" --json >"$tmp/transcript.json"
else
cp -- "$tmp/response-0.json" "$tmp/transcript.json"