How to Play a Sound in Windows with Python

preview_player
Показать описание
Learn how to play sounds using the Python winsound module. Note, this only works on Windows computers (and ReactOS).
►►►►LINKS

►►►►LEARN MORE PYTHON

**AND**

►►►►LEARN MORE JAVA
Рекомендации по теме
Комментарии
Автор

For anyone having problems:
1. Right click on the file that you want to use
2.Click on Properties
3.Look at where it says Location
4. Copy and paste it into where he said to put file name
5. Change the back slashes to forward slashes
6. Add /name of your file to the end of where you put the location
(You must put a forward slash then name of file)
Eg. /shoot.wav

Hope that helps!

oj_
Автор

Other people have most likely already said this, but just incase, this is what finally got it to work for me.

1. Press the windows key
2. Enter in a little bit of the file name so it comes up
3. Right click on it so that 2 options come up.(it could be more than 2 options)
4. One of the options will be "Copy full path". Click that
5. Paste what you just copied into where it says FILENAME within this bit of code here - winsound.PlaySound(“FILENAME”, winsound.SND_ASYNC)
6. Switch all the slashes in the thing you copied from this--->\ to this--->/

That way it is impossible to mess up the full path.

Thank you TokyoEdtech for putting up this video :)

aaronbelikoff
Автор

Great and fast video, the best part of this is that it allows you to play sound while reading the next code lines!

secret
Автор

Came here from your space invaders tutorial. Glad you checked into this for us Windows users...

gordonspond
Автор

How come mine plays the windows error sound and then the correct sound? I have the full path there.

kod
Автор

I haven't imagined it is so simple to play sounds in python, thanks a lot

tahep
Автор

Thanks! I was following your tutorial of "Space invaders" and here I am!

johnkim
Автор

thank you soo much i tried to do this a billion times from other tutorials only your way worked

hussanxgh
Автор

when i try this i get the windows notfication sound

wess
Автор

Im doing that pong tutorial u made but everytime the ball hits the top it makes the windows error noise instead of the bounce noice and i did exactly as u said in ur vid.

Oswaldosan
Автор

Those whom error sound is coming:
Right on file -> Properties -> [copy file location] -> Replace Forward slash with Back Splash -> Paste in:
winsound.PlaySound("[File Location]", winsound.SND_ASYNC)
For example:
import winsound
winsound.PlaySound("H:/Coding/Python/pong/pong/bounce.wav", winsound.SND_ASYNC)
Hope it helps...

parthteja
Автор

Thank you I appreciate your help for all of us. I did hear the sound. That's good to know that it will work in the back ground so it doesn't stop the game in motion.

ScreenPrintR
Автор

I tried your method, but instead of my sound, the default windows_notification_sound was played. idk why lol. So I wrote the whole path to the sound like and it worked. thanks a ton.
p.s.: Im on win7

IAmfreeeeeeeeeee
Автор

Thank you so much. Now i could complete your tutorials for mac on my win 10 pc.

clashwithnumaan
Автор

"Alot of people use windows. I don't know why" Lol. Ever heard of gaming?

skyler
Автор

Answering your question at 1:40, in my specific case, as a blind person, I find it easier to find accessible programs for Windows than for Linux and at least here in Brazil, a computer with Windows costs less than an Apple computer, which has a lot of accessibility as far as I know, even considering VoiceOver - Apple's screen reader. Surely there is Orca - a screen reader for Linux if you use GNOME, but QWS - a MIDI editor for Windows is much easier than Denemo, for example.

By the way, what do you think of using Pygame for playing sounds? That would provide a multi-plataform solution, wouldn't it?

supermalavox
Автор

I don’t get an error message but the music doesn’t play.

LegendaryPros
Автор

Can you share the link to those sounds

adityajagtap
Автор

we use windows because everything is made for it. Steam games etc. I know this is an old video but please don't. I also don't want to do everything from a command line. I have a NAS that runs on UNIX and I was able to set it up as a 12 year old. In Unix. I know it's good for user control but I can always just write a script in C# or whatever.

jacobdaniels
Автор

tnx man this was the most helpful video about winsound

tongqiu
join shbcf.ru