wavio is a useful module that is focused on converting between WAV files and NumPy arrays. Remember how in the recording with the
python-sounddevice example, you had to use a
SciPy module to convert the NumPy array to a WAV file?
Using the same sample rate and the same length of time, just about everything stays the same until you get to this
write() line. So let’s go ahead and comment this out and see how
wavio would look.
And actually, this is just
sampwidth. And that’s all there is to it! To reiterate, if you don’t want to use
SciPy to convert your NumPy arrays to WAV files, you can use
wavio. And looking at its usage, it’s not that much different. You’re still going to define the filename, the sample rate, the array, and then you do have to define the sample width again, but that’s not too difficult. Remember that NumPy arrays are great when you need to create or modify sound data, due to their mutability.
wavio a great way to convert a
bytes object WAV file into a NumPy array, and then convert it back into a WAV file when you’re done. Next, we’ll talk about
soundfile, which will let you convert a WAV file into a FLAC, AIFF, and a couple other formats. Thanks for watching.
Become a Member to join the conversation.