winsound
00:00
If you’re on Windows, winsound
is a good option as it’s built into Python. Its usage is very similar to playsound
from earlier. Inside your text editor, go ahead and import winsound
.
00:17
Define your filename
, so for me let’s do 'hello.wav'
.
00:23
And then using winsound
, call the PlaySound()
method. And in here, pass in the filename
and then add in this winsound.SND_FILENAME
.
00:39
And this SND_FILENAME
is just saying that the sound that you’re passing into here is a filename. So, this won’t work for me because I’m on a Mac right now, but you should get the idea.
00:51
Keep in mind that winsound
only works for WAV files, so if you’re using MP3s, it won’t work. A cool thing that winsound
can do is beep the speakers on your PC by calling the Beep()
method. Let’s just comment this out real quick.
01:08
And if you call winsound
, you can say Beep()
, and if you wanted to do a 1000 Hz tone for 100 milliseconds, you could just do that. For a project that’s going onto a PC, this can be a great way to notify a user that something has happened. Just by adding one line of code, you can add in beeps of different frequencies for different durations without needing to create your own sounds or import different filenames.
01:35
All right. In the next video, we’re going to cover python-sounddevice
, which is a NumPy array based player.
Become a Member to join the conversation.