audiocraft icon indicating copy to clipboard operation
audiocraft copied to clipboard

I get this error: FileNotFoundError: [Errno 2] No such file or directory: '/content/9SNAXgNm3D6r.mp4

Open demiguelm opened this issue 1 year ago • 2 comments

Trying to run locally :(

demiguelm avatar Jun 10 '23 17:06 demiguelm

It may be related, albeit 1. I am not sure why you are getting .mp4 (should be .wav or .mp3 ?!) and 2. it was Windows in my case (and using the melody model, where saving the file is the default):

TypeError: Invalid file: WindowsPath('C:/Users/zer0int/audiocraft/0.wav.wav')

I modified the code snippet provided in the readme.md slightly to use absolute paths:

svpt="C:/Users/zer0int/audiocraft/"

for idx, one_wav in enumerate(wav):
    # Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
    file_path = os.path.join(svpt, f'{idx}.wav')
    audio_write(file_path, one_wav.cpu(), model.sample_rate, strategy="loudness")

I turned to GPT-4 with the error (and the code in the files as of the Traceback of the error), and the AI suggested the issue is at <Pythonpath>\site-packages\audiocraft\data\audio.py:207, with the fix being:

def audio_write(stem_name: tp.Union[str, Path],
                # ...
                make_parent_dir: bool = True,
                add_suffix: bool = True) -> Path:
    # ...
    path = Path(str(stem_name) + suffix)
    if make_parent_dir:
        path.parent.mkdir(exist_ok=True, parents=True)
    try:
        ta.save(str(path), wav, sample_rate, **kwargs)  # Explicitly convert the path to a string here.
    except Exception:
        if path.exists():
            path.unlink()
        raise
    return path

Alas, adding "str" to "ta.save(str(path)" fixed the problem for me. Thanks, GPT-4!

zer0int avatar Jun 12 '23 10:06 zer0int