Skip to content

fix(transcription): load PCM WAV via stdlib to skip PyAV decode#34

Merged
BBC-Esq merged 1 commit into
BBC-Esq:mainfrom
webenefits:fix/native-wav-loader-bypass-pyav-locale-bug
Apr 2, 2026
Merged

fix(transcription): load PCM WAV via stdlib to skip PyAV decode#34
BBC-Esq merged 1 commit into
BBC-Esq:mainfrom
webenefits:fix/native-wav-loader-bypass-pyav-locale-bug

Conversation

@webenefits

Copy link
Copy Markdown
Contributor

Problem - on Linux (CachyOS)
Transcription after recording can fail with UnicodeDecodeError (e.g. 'ascii' codec can't decode byte …) in av.error.err_check when PyAV decodes FFmpeg error paths as ASCII. This shows up on some locales (e.g. German) when FFmpeg/PyAV surfaces non-ASCII text.

Cause
faster-whisper decodes and resamples via PyAV; FFmpeg error handling can expose non-ASCII strings, and PyAV may decode them incorrectly. In-app recordings are standard PCM WAV.

Solution
For supported .wav files (16-bit PCM, mono or stereo), load audio with the stdlib wave module and NumPy, optionally downmix stereo to mono, linearly resample to feature_extractor.sampling_rate (16 kHz), and pass a float32 np.ndarray into transcribe / BatchedInferencePipeline.transcribe so faster-whisper skips decode_audio. Unsupported WAV variants and all non-WAV inputs keep the previous behavior (file path string → PyAV pipeline unchanged).

Testing

  • Synthetic 44.1 kHz mono int16 WAV through the loader (resampled length ~16k at 16 kHz).
  • Non-.wav path still yields None → string path unchanged.

Prepared with assistance from Cursor (AI editor). I have tested the changes locally, please still give the patch a careful review before merging.

Decode 16-bit PCM WAV (mono/stereo) with the wave module, resample to the
model sample rate, and pass float32 audio to faster-whisper. This bypasses
PyAV/FFmpeg for typical recordings and avoids UnicodeDecodeError on some
locales when error paths contain non-ASCII text.

Non-WAV and unsupported WAV formats still use the file path and the
existing PyAV pipeline.
@gemini-code-assist

Copy link
Copy Markdown

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@BBC-Esq

BBC-Esq commented Apr 1, 2026

Copy link
Copy Markdown
Owner

Can you confirm that you're real? I went to the github account and it's barren.

@webenefits

Copy link
Copy Markdown
Contributor Author

Hi, yes, I'm real.
Actually, we're not developers, we're a web agency, which is why there isn't much activity on our GitHub account. But we're big fans of open source, and in our opinion, that includes sharing code when you've improved or fixed something for yourself.
Best regards,
Web-Benefits

@BBC-Esq BBC-Esq merged commit 13ca0b1 into BBC-Esq:main Apr 2, 2026
@BBC-Esq

BBC-Esq commented Apr 2, 2026

Copy link
Copy Markdown
Owner

Congratulations on your first contribution to this project! Great catch on the PyAV locale issue — clean implementation with a solid fallback. Merged!

@webenefits

Copy link
Copy Markdown
Contributor Author

Thank you very much, I'm glad to hear that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants