MAC M3 audio backend no longer appearing
🐛 Description
I get "RuntimeError: Couldn't find appropriate backend to handle uri <_io.BytesIO object at 0x13f1f8450> and format None." when processing basic audio data on my mac but not on my colab notebook.
Full code is here `import torchaudio print(torchaudio.list_audio_backends()) def read_audio_from_stream(audio_stream, sampling_rate: int = 16000): sox_backends = set(['sox', 'sox_io']) audio_backends = torchaudio.list_audio_backends()
if len(sox_backends.intersection(audio_backends)) > 0:
effects = [
['channels', '1'], # Force mono
['rate', str(sampling_rate)] # Resample to the target sampling rate
]
wav, sr = torchaudio.sox_effects.apply_effects_file(audio_stream, effects=effects)
else:
# Load the audio file from the stream
wav, sr = torchaudio.load(audio_stream)
# If more than one channel, take the mean to make it mono
if wav.size(0) > 1:
wav = wav.mean(dim=0, keepdim=True)
# Resample if necessary
if sr != sampling_rate:
transform = torchaudio.transforms.Resample(orig_freq=sr, new_freq=sampling_rate)
wav = transform(wav)
sr = sampling_rate
assert sr == sampling_rate, "Sampling rate does not match the target sampling rate"
return wav.squeeze(0) `
where torchaudio.list_audio_backends() always prints to empty []. I tried uninstalling and then reinstalling with `pip install torch torchaudio -f https://download.pytorch.org/whl/torch_stable.html`, I also installed sox. ffmpeg is already installed on my mac. I've seen this pop up on stack overflow 3 times this month as well but no one has come up with an answer. It seems pretty trivial to work for torchaudio.
Versions
torch==2.3.0 torchaudio==2.3.0
same here, reinstall ffmpeg:
brew install ffmpeg@6
brew install sox
then reinstall torchaudio won't work, torchaudio.list_audio_backends() always prints to empty []
hardware: mac osx m3 max
I've been experiencing the same issue.
I think I have figured out a solution but don't have time to properly test what I've done. I've followed the advice here: https://pytorch.org/audio/stable/build.linux.html in a fresh conda environment, including the "[Optional] Build TorchAudio with a custom built FFmpeg" section. I've just change the line to install ffmpeg to conda install -c conda-forge ffmpeg=6 (i.e., I've specified that the ffmpeg libraries should come from ffmpeg 6.something).
Please forgive this uninformative message!
here is my solution on mac:
brew install ffmpeg@5
and make sure to the lib to path:
export PATH="/opt/homebrew/opt/ffmpeg@6/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/ffmpeg@6/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ffmpeg@6/include"
then reinstall torchaudio