soundfile is a powerful library that we’ve already used to read WAV files for the
python-sounddevice example. Any file format supported by
libsndfile (lib sound file) can be handled by
soundfile. Even though
soundfile won’t play audio for you, it can be used to convert between all these different types. For example, let’s convert one of our WAV files to a FLAC file. In the editor, you’re going to
import soundfile as sf,
and then now let’s just call it
'hello.flac'. You’ll want to pass in the audio data and the sample rate.
soundfile will take a look at the extension you use, and if it’s one that’s supported by it, it will automatically convert to that file type.
Let’s see if this works. Go
python python_sounds, and look at that! The WAV file has now been saved as a FLAC file. So, that’s pretty cool! Take a look at the list of file formats that are supported by
soundfile, and if it includes what your project needs, this is a great way to perform any conversions that you need. Okay!
Become a Member to join the conversation.