How to solve RuntimeError: Couldn't find appropriate backend to handle uri in python

535 Views Asked by At

I want to work with audiofiles in pytorch.

If I try running this line: metadata = torchaudio.info(SAMPLE_WAV_PATH) i get the error message RuntimeError: Couldn't find appropriate backend to handle uri _assets\steam.wav and format None

the internet told me to try str(torchaudio.list_audio_backends()) to see if I have soundfile installed. It appears I don't, because it returns an empty list.

So I tried installing soundfile. Here is a list of commands i tried:

  • conda install pytorch torchvision torchaudio -c pytorch
  • conda install -c conda-forge pysoundfile
  • pip install soundfile
  • pip install PySoundFile

none of it made a difference. According to the anaconda navigator I have both pysoundfile and soundfile installed, but I still get the same error message. I searched for similar problems and found questions like this cannot import torch audio ' No audio backend is available.' But the only answeres there say I should install soundfile

If somebody got an idea whats wrong I would appreciate some help, thanks in advance.

EDIT I am using windows 11

1

There are 1 best solutions below

2
Jonny Henly On

On my Windows 11 machine with:

  • C:\Users\Foo>python3 --version
    Python 3.12.2
    
  • C:\Users\Foo>pip3 --version
    pip 24.0 from C:\Users\Foo\PathToPython312\site-packages\pip (python 3.12)
    
  • C:\Users\Foo>pip3 show torch torchvision torchaudio PySoundFile
    WARNING: Package(s) not found: torch torchvision torchaudio PySoundFile
    

    No previous installs of torch, torchvision, torchaudio or PySoundFile


I opened command prompt (not as administrator) and ran:

pip3 install torch torchvision torchaudio

Which installed:

torch              2.2.1
torchaudio         2.2.1
torchvision        0.17.1

Note: several other dependency packages were installed along with the packages above.

I then ran python3 ./test.py:

# ./test.py

import torchaudio
print(str(torchaudio.list_audio_backends()))

Which output an empty list:

[]

So I then ran:

pip3 install PySoundFile

Which installed:

PySoundFile        0.9.0.post1

I then re-ran python3 ./test.py which output:

['soundfile']

I suggest uninstalling all related packages:

pip3 uninstall torch torchvision torchaudio PySoundFile

You'll probably also want to uninstall soundfile, since it's in the list of commands you tried.

I would then inspect the output of pip3 list and ensure the packages are no longer there. Then follow the steps I took above, in order, and see if you can get ['soundfile'] as output.

Note: I do not use anaconda, so if the steps above do not resolve your issue then I'd say there's a good chance that it's causing the problem.