audiocraft
audiocraft copied to clipboard
download the Tensor object at the end of the generation
When the program runs on collab, i was wondering if there is an easy way to download the wav file.
The usual:
from google.colab import files files.download(res)
doesn't work on Tensor objects. I tried to convert it to wav or mp3 to no avail. I tried modifying utils/notebook.py display_audio function and i couldn't figure it out.
Does anyone knows how to take the samples and samples_rate and create the wav (or mp3) file? Is Torchaudio the right library for that purpose?
Try this:
import soundfile as sf
from google.colab import files
import numpy as np
sf.write('audio.wav', np.squeeze(np.array(res.cpu()).T), 32000)
files.download('audio.wav')
Thank you very much @NaJeongMo , it works!
As an interesting sidenote, i was not aware of the library soundfile, as i don't program in python. I filed the issue after googling and experimenting with code found on stackoverflow and other sites, and not going anywhere. Only today it dawned me, to ask ChatGpt the same question, and it came up with soundfile in one second.
Anyway, i created a copy of the audiocraft notebook, which features automatically file download, and it can be found here
https://colab.research.google.com/drive/1eJbjeOLoK3XIGM9rWmJFZxH1zdX0Fi7A?usp=sharing