audiocraft icon indicating copy to clipboard operation
audiocraft copied to clipboard

RuntimeError: Failed to load audio from ./assets/bach.mp3

Open seven54 opened this issue 1 year ago • 2 comments

The apt-get install ffmpeg command is installed. implement import torchaudio from audiocraft.models import MusicGen from audiocraft.data.audio import audio_write

model = MusicGen. get_pretrained('melody') model.set_generation_params(duration=8) # generate 8 seconds. wav = model.generate_unconditional(4) # generates 4 unconditional audio samples descriptions = ['happy rock', 'energetic EDM', 'sad jazz'] wav = model. generate(descriptions) # generates 3 samples.

melody, sr = torchaudio.load('./assets/bach.mp3')

generates using the melody from the given audio and the provided descriptions.

wav = model.generate_with_chroma(descriptions, melody[None].expand(3, -1, -1), sr)

for idx, one_wav in enumerate(wav): # Will save under {idx}.wav, with loudness normalization at -14 db LUFS. audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True) An error occurred RuntimeError: Failed to load audio from ./assets/bach.mp3

seven54 avatar Jun 24 '23 07:06 seven54

as i understand rn torch audio is not supporting mp3?? (even if you using format="mp3") you should convert mp3 to wav and then use torch audio

wwardaww avatar Jun 29 '23 23:06 wwardaww

i also meet this problem, and after i convert mp3 to wav and then use torch audio to load wav file ,it works

luoruijie avatar Jul 11 '23 05:07 luoruijie

Yes, converting to wav works.

seven54 avatar Jul 26 '23 04:07 seven54