简体   繁体   中英

How to export an "IPython.lib.display.Audio" file as a mp3 or wav file?

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.

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)
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM