python-sounddevice (Part 1)
python-sounddevice provides bindings for the PortAudio library and a few convenience functions to play and record NumPy arrays containing audio signals. Because of this, it has a few dependencies to open WAV files and work with NumPy arrays.
Then you’re going to want to save the data and the sampling rate from that WAV file. So set
fs equal to
sf.read(), and then you’re going to pass in the
filename and then a
dtype (data type), for which you’ll just want
soundfile.read() is going to read the audio data from that WAV file and then also take a look at the headers to get that sampling rate for you.
There we go. Try again. “Hey there, this is a WAV file.” All right, that worked! Now you should know how to use
python-sounddevice to play files, and you’ll see later on, you can actually use this library to record sound as well. In the next video, you’re going to learn how to use
pydub, which handles quite a few different audio formats.
Become a Member to join the conversation.