I have generated a music file for the first time. The music file type is "IPython.lib.display.Audio". I wanted to export it from colab to my local drive.I couldn't find any solution from google. Please help.
How to export an "IPython.lib.display.Audio" file as a mp3 or wav file?
Asked Answered
The wave file content is stored in the data
field, you may write the content to a file like this:
with open('/tmp/test.wav', 'wb') as f:
f.write(audio.data)
But this saves to the remote server in which the python is running on. How to download using the browser? –
Grommet
in my case, this works with google colab, not jupyter notebook; but anyway, thanks; I ran code in jupyter notebook to display audio, then upload file to google colab for downloading –
Guano
soundfile.write(output_filename, audio_data, sample_rate)
output_filename: The output filename or a path to the output file
audio_data: The <class 'IPython.lib.display.Audio'>
object
sample_rate: Based on your need.
https://pysoundfile.readthedocs.io/en/latest/#read-write-functions also gives a brief example. This should work whether you use colab/jupyter notebook or not.
© 2022 - 2024 — McMap. All rights reserved.