diff --git a/README.md b/README.md index 84f6d04..94d4691 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ export OPENROUTER_API_KEY='sk-or-v1-...' ``` Accepts m4a, mp4, aac, flac, opus, mp3, ogg, wav, and other formats your -FFmpeg supports. Uses the first audio track, converts it to mono 16 kHz WAV, +FFmpeg supports. Uses the first audio track, converts it to mono 16 kHz MP3 +at 64 kbps (requires FFmpeg's libmp3lame encoder), and sends it to OpenRouter's `microsoft/mai-transcribe-2` model. Temporary files are removed on exit. The transcript goes to stdout; errors to stderr. diff --git a/transcribe b/transcribe index 4f0d68d..41933a3 100755 --- a/transcribe +++ b/transcribe @@ -29,12 +29,12 @@ trap 'exit 143' TERM # Normalize any FFmpeg-readable audio (or the first audio track in a video). ffmpeg -nostdin -hide_banner -loglevel error -i "$(realpath -- "$1")" \ - -map 0:a:0 -ac 1 -ar 16000 -c:a pcm_s16le "$tmp/audio.wav" + -map 0:a:0 -ac 1 -ar 16000 -c:a libmp3lame -b:a 64k "$tmp/audio.mp3" # Keep large audio payloads out of shell arguments (which have a size limit). -base64 <"$tmp/audio.wav" | tr -d '\n\r' >"$tmp/audio.b64" +base64 <"$tmp/audio.mp3" | tr -d '\n\r' >"$tmp/audio.b64" jq -n --rawfile data "$tmp/audio.b64" \ - '{model: "microsoft/mai-transcribe-2", input_audio: {data: $data, format: "wav"}}' \ + '{model: "microsoft/mai-transcribe-2", input_audio: {data: $data, format: "mp3"}}' \ >"$tmp/request.json" curl --silent --show-error --fail-with-body \