Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError in torchaudio_sox::load_audio_file() #27

Open
kgoba opened this issue May 11, 2024 · 2 comments
Open

RuntimeError in torchaudio_sox::load_audio_file() #27

kgoba opened this issue May 11, 2024 · 2 comments

Comments

@kgoba
Copy link

kgoba commented May 11, 2024

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
Copy link

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

@vanliyan
Copy link

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.

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

No branches or pull requests

2 participants