Skip to content

Add ffmpeg fallback for audio formats libsndfile cannot decode (M4A/AAC) - #1267

Open
GuxtavoLiu wants to merge 1 commit into
IAHispano:mainfrom
GuxtavoLiu:fix/ffmpeg-fallback-unsupported-audio
Open

Add ffmpeg fallback for audio formats libsndfile cannot decode (M4A/AAC)#1267
GuxtavoLiu wants to merge 1 commit into
IAHispano:mainfrom
GuxtavoLiu:fix/ffmpeg-fallback-unsupported-audio

Conversation

@GuxtavoLiu

Copy link
Copy Markdown

Problem

Uploading an M4A/AAC file to inference fails with:

RuntimeError: An error occurred loading the audio: Error opening 'assets/audios/recording.m4a': Format not recognised.

M4A is the default output of the Windows Sound Recorder and of WhatsApp voice notes, so this is a common first experience for new users: they record something, upload it, and conversion fails with a generic error.

Root cause: load_audio / load_audio_infer read files with soundfile (libsndfile), which does not decode AAC.

Fix

Add a small read_audio_any helper in rvc/lib/utils.py: try sf.read first and, if libsndfile cannot open the file, decode it with ffmpeg (mono float32 at the requested sample rate, piped via stdout, no temp files).

  • No behavior change for formats libsndfile already handles (wav, flac, mp3, ogg): sf.read still handles those.
  • No new Python dependency; uses the ffmpeg binary from PATH.
  • If ffmpeg is not available, the original LibsndfileError is re-raised, so systems without ffmpeg see the same error as today.
  • Decoding at the requested sample rate also skips the extra librosa resample step in that path.

Testing

Tested on Windows 11 (RTX 3060, CUDA build) by running core.py infer with an M4A recording from the Windows Sound Recorder: fails with 'Format not recognised' before the patch, converts normally after it. Also verified that WAV inference still works unchanged.

🤖 Generated with Claude Code

Uploading M4A/AAC recordings (the default format of the Windows Sound
Recorder and WhatsApp voice notes) fails at inference with
'Format not recognised' because libsndfile cannot decode AAC.

When soundfile fails to open a file, decode it with ffmpeg instead
(mono float32 at the requested sample rate). Behavior is unchanged for
formats libsndfile already handles and for systems without ffmpeg on
PATH, which re-raise the original error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@thelabcat

thelabcat commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

If this does what you say it does, that sounds awesome! I haven't reviewed the code, but thanks.

@AznamirWoW

Copy link
Copy Markdown
Contributor

Honestly, the audio load should be done using ffmpeg as it does not zap the top end of the audio spectrum.

@blaisewf

blaisewf commented Aug 4, 2026

Copy link
Copy Markdown
Member

#1269

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.

4 participants