fix(parakeet-cpp): convert audio before the non-batched transcribe path#10161
Merged
Conversation
The direct (non-batched) transcription path handed the original upload path straight to the C library via parakeet_capi_transcribe_path_json. That loader only understands 16 kHz mono WAV/PCM, so any other format (MP3, etc.) failed with "parakeet: failed to load audio: <file>". Only the batched path converted the input (via decodeWavMono16k -> utils.AudioToWav). Every other audio backend (whisper, crispasr) converts unconditionally with utils.AudioToWav before handing the file to its engine; the parakeet-cpp fallback was the lone exception. Extract a convertToWavMono16k helper (reused by decodeWavMono16k) that produces a 16 kHz mono WAV in a temp dir, and run the non-batched path through it before calling the C loader. WAV inputs already in the target format are passed through without ffmpeg. Add specs covering the helper (decodable copy + cleanup, and an error on a missing input) that need neither the model, the C library, nor ffmpeg. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:claude-opus-4-8 [Claude Code]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Transcribing a non-WAV file (e.g. MP3) through the
parakeet-cppbackend fails:Root cause
AudioTranscriptioninbackend/go/parakeet-cpp/goparakeetcpp.gohas two paths:p.bat != nil): decodes viadecodeWavMono16k→utils.AudioToWav(ffmpeg), so any format works.p.bat == nil, used when the batched C-API symbol isn't present inlibparakeet.so): handed the original upload path straight toparakeet_capi_transcribe_path_json. That C loader only understands 16 kHz mono WAV/PCM, so MP3 (and anything non-WAV) fails withfailed to load audio.LocalAI does no conversion at the HTTP/service layer — it delegates format handling to each backend. Every other audio backend converts unconditionally with
utils.AudioToWavbefore calling its engine (whispergowhisper.go:189/299,crispasrgocrispasr.go:186/291). The parakeet-cpp direct path was the lone exception.Fix
convertToWavMono16k(path)→(wavPath, cleanup, err)that produces a 16 kHz mono WAV in a temp dir. WAV inputs already in the target format are passed through without ffmpeg.CppTranscribePathJSON.decodeWavMono16kto reuse the helper (no duplication).Tests
Added specs that need neither the model, the C library, nor ffmpeg (they use an already-target-format WAV that
AudioToWavpasses through):convertToWavMono16kreturns a decodable temp-WAV copy (not the original path) andcleanup()removes it.golangci-lint run ./backend/go/parakeet-cpp/→0 issues.Assisted-by: Claude:claude-opus-4-8 [Claude Code]
🤖 Generated with Claude Code