How to save the audio file using ipd.display?
Just a minimal sample here
from IPython.display import Audio
from IPython.core.display import display
import librosa
audio_data, sample_rate = librosa.load('/Users/0_hey.wav', sr=None)
ipd.Audio(audio_data, rate=sample_rate)
Then it plays a sound, but I don't know how to save the audio file.
I know that we can download it by clicking the right bottom.
But I hope it can also be written in codes.
The display.Audio is a widget, a user interface component that provides Audio controls. After the docs:
When this object is returned by an input cell or passed to the display function, it will result in Audio controls being displayed in the frontend (only works in the notebook).
audio_data is a numpy array and you can use any library that works with such data structures. PySoundFile is a solid choice, also recommended by librosa, library that you are using.
import soundfile as sf
# Write out audio as 24bit flac, change accordingly
sf.write('audio.flac', audio_data, sample_rate, format='flac', subtype='PCM_24')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With