Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Playing and Recording Sound in Python (Summary)

Download

Sample Code (.py)

2.9 KB
Download

Course Slides (.pdf)

259.7 KB

00:00 Congratulations! You’ve learned how to use a large number of libraries related to working with audio in Python. In this video, we’re going to recap each of them and briefly cover what they’re used for so you can quickly decide if they’ll fit your next project or not. First, we have playsound, which is a good general purpose cross-platform audio player.

00:21 It plays WAV files and MP3s and doesn’t require any dependencies.

00:26 simpleaudio is where we brought in NumPy array support. It’s also cross-platform and it can play WAV files, but also NumPy arrays or byte objects. It also doesn’t require dependencies, but it will need NumPy if you want to use NumPy arrays.

00:42 winsound was the Window’s WAV player. It only works on Windows and it only supports WAV playback, but it doesn’t require any dependencies and it allows you to beep the computer speakers in a single line of code.

00:55 python-sounddevice is where you got into recording with Python. It’s cross-platform and it can play and record NumPy arrays. Because of this, it requires NumPy and it also requires soundfile.

01:08 pydub is a good general purpose audio player and converter. Like most of the libraries here, it’s cross-platform, and it can play and convert any audio format supported by ffmpeg.

01:20 It requires simpleaudio and ffmpeg. pyaudio was the low-level audio player and recorder. It’s cross-platform and can play and record byte objects.

01:32 Remember that PyAudio required more code than some of the other libraries. This is what allows it to have tighter control on the audio input and output, so you’ll need to decide if your project requires that. pyaudio requires the wave library. wavio was the WAV and array converter. It’s cross-platform, and it’s really good at converting between WAV files and NumPy arrays. To do this, it requires NumPy and wave. And finally, soundfile, which is a cross-platform audio converter. soundfile won’t play back any files, but it can convert any file type supported by libsndfile. To do this, it requires CFFI, libsndfile, and NumPy.

02:17 And that’s all there is to it! Hopefully by now you have a solid grasp on how to incorporate audio into your Python projects. We only scratched the surface on all of these libraries, so if any of them interested you, you should check out their documentation and see how you can customize them to do exactly what you need.

02:35 Audio can really add to an application as it can give information to the user without printing to a terminal or generating graphics onscreen. Keep this in mind and see if it’s possible to add audio to your next project.

02:49 Thanks for watching.

rolandgarceau on Feb. 20, 2020

Has anyone tried to make system level sounds for the MBP?

Pygator on March 1, 2020

I think it is much better if the source code and a description of each video is available under each video. I have found this helps me learn much better. I’d like to know what other learners think? Chris Baileys videos do this and i find i remember his lessons much better by reading his explantions first, then watching the video, and experimenting with the code under the video last. But otherwise i think the content is interesting.

Joe Tatusko RP Team on March 2, 2020

Thanks for the feedback Pygator! The code used in the videos is provided as a download (all in one file, so you would need to break it out to test), but are you looking for the code in the actual description of the video?

Become a Member to join the conversation.