Torchaudio compatibility issue with Wav files on Ubuntu WLS2

167 views Asked by At

This repo https://github.com/facebookresearch/brainmagick works fine on Ubuntu vanilla. On the exact same WLS2 configuration, the following error arises. This is using torchaudio 2.2.1.

The issue is that torchaudio fails to autodetect the audio file type (wav) in this case.

Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/concurrent/futures/process.py", line 246, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/home/ubuntu/brainmagick_abdhu/bm/dataset.py", line 381, in _preload
    recording.events()
  File "/home/ubuntu/brainmagick_abdhu/bm/studies/api.py", line 264, in events
    self._events = self._load_events()
  File "/home/ubuntu/brainmagick_abdhu/bm/studies/brennan2019.py", line 307, in _load_events
    events = _read_meta(file)
  File "/home/ubuntu/brainmagick_abdhu/bm/studies/brennan2019.py", line 167, in _read_meta
    events = events.event.create_blocks(groupby='sentence')
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/site-packages/pandas/core/accessor.py", line 224, in __get__
    accessor_obj = self._accessor(obj)
  File "/home/ubuntu/brainmagick_abdhu/bm/events.py", line 549, in __init__
    self._frame = self.validate()
  File "/home/ubuntu/brainmagick_abdhu/bm/events.py", line 603, in validate
    return pd.DataFrame(self._frame.apply(self._validate_event, axis=1).tolist())
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/site-packages/pandas/core/frame.py", line 10034, in apply
    return op.apply().__finalize__(self, method="apply")
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/site-packages/pandas/core/apply.py", line 837, in apply
    return self.apply_standard()
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/site-packages/pandas/core/apply.py", line 963, in apply_standard
    results, res_index = self.apply_series_generator()
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/site-packages/pandas/core/apply.py", line 979, in apply_series_generator
    results[i] = self.func(v, *self.args, **self.kwargs)
  File "/home/ubuntu/brainmagick_abdhu/bm/events.py", line 586, in _validate_event
    event_obj = event_class.from_dict(event)
  File "/home/ubuntu/brainmagick_abdhu/bm/events.py", line 53, in from_dict
    return cls(**{k: v for k, v in row.items() if k in [f.name for f in fields(cls)]})
  File "<string>", line 9, in __init__
  File "/home/ubuntu/brainmagick_abdhu/bm/events.py", line 132, in __post_init__
    info = torchaudio.info(self.filepath)
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/site-packages/torchaudio/_backend/utils.py", line 97, in info
    backend = dispatcher(uri, format, backend)
  File "/home/ubuntu/anaconda3/envs/p310env/lib/python3.10/site-packages/torchaudio/_backend/utils.py", line 53, in dispatcher
    raise RuntimeError(f"Couldn't find appropriate backend to handle uri {uri} and format {format}.")
RuntimeError: Couldn't find appropriate backend to handle uri /home/ubuntu/brainmagick_abdhu/data/brennan2019/download/audio/DownTheRabbitHoleFinal_SoundFile1.wav and format None.
"""
1

There are 1 answers

0
user1097111 On

It turned out that this is an issue with the SOX audio library that cannot autodetect wav files. Installing the "soundfile" and uninstalling SOX worked.