facebookresearch / audiocraft

Audiocraft is a library for audio processing and generation with deep learning. It features the state-of-the-art EnCodec audio compressor / tokenizer, along with MusicGen, a simple and controllable music generation LM with textual and melodic conditioning.
MIT License
20.92k stars 2.14k forks source link

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

Closed seven54 closed 1 year ago

seven54 commented 1 year ago

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

wwardaww commented 1 year ago

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

luoruijie commented 1 year ago

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

seven54 commented 1 year ago

Yes, converting to wav works.