resemble-ai / resemble-enhance

AI powered speech denoising and enhancement
https://huggingface.co/spaces/ResembleAI/resemble-enhance
MIT License
1.08k stars 103 forks source link

RuntimeError in torchaudio_sox::load_audio_file() #27

Open kgoba opened 1 month ago

kgoba commented 1 month ago

torchaudio_sox::load_audio_file() seems to expect str, not PosixPath (not sure why though):

Traceback (most recent call last):
  File "/Users/bwords/Devel/nightingale/./venv/bin/resemble-enhance", line 8, in <module>
    sys.exit(main())
  File "/Users/bwords/Devel/nightingale/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/Users/bwords/Devel/nightingale/venv/lib/python3.10/site-packages/resemble_enhance/enhancer/__main__.py", line 94, in main
    dwav, sr = torchaudio.load(path)
  File "/Users/bwords/Devel/nightingale/venv/lib/python3.10/site-packages/torchaudio/_backend/utils.py", line 205, in load
    return backend.load(uri, frame_offset, num_frames, normalize, channels_first, format, buffer_size)
  File "/Users/bwords/Devel/nightingale/venv/lib/python3.10/site-packages/torchaudio/_backend/sox.py", line 44, in load
    ret = sox_ext.load_audio_file(uri, frame_offset, num_frames, normalize, channels_first, format)
  File "/Users/bwords/Devel/nightingale/venv/lib/python3.10/site-packages/torch/_ops.py", line 755, in __call__
    return self._op(*args, **(kwargs or {}))
RuntimeError: torchaudio_sox::load_audio_file() Expected a value of type 'str' for argument '_0' but instead found type 'PosixPath'.
Position: 0
Value: PosixPath('tmp/myfile.wav')
Declaration: torchaudio_sox::load_audio_file(str _0, int? _1, int? _2, bool? _3, bool? _4, str? _5) -> (Tensor _0, int _1)
Cast error details: Unable to cast Python instance of type <class 'pathlib.PosixPath'> to C++ type '?' (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)

Environment: Mac OS Ventura, python 3.10, venv

vanliyan commented 1 month ago

You can temporary fix this by casting the path to str. path = str(path)

vanliyan commented 1 month ago

You can temporary fix this by casting the path to str. path = str(path)

Also be careful that you need to actually do the same for torchaudio::sox_io_save_audio_file() too, otherwise you waste your time and won't be able to save the conversion.