Created
February 2, 2019 17:49
-
-
Save MrDMurray/fc11585c2072f0dff04b3d0f7c988b72 to your computer and use it in GitHub Desktop.
winsound errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import winsound | |
#List of mistakes I have made using winsound: | |
######################################################################## | |
# I hear nothing? | |
######################################################################## | |
winsound.PlaySound("", winsound.SND_FILENAME) | |
#You hear nothing because you're missing your sound name | |
######################################################################## | |
# "Windows Error Sound" errors | |
######################################################################## | |
winsound.PlaySound("IDoNotExist", winsound.SND_FILENAME) | |
# You hear the WINDOWS ERROR SOUND PING! because that there's no | |
# such .wav sound file called IDoNotExist in the same folder as your python file. | |
# If there is a file there, maybe check the spelling is correct. | |
winsound.PlaySound(" hey.wav", winsound.SND_FILENAME) | |
# You hear the WINDOWS ERROR SOUND PING! because you left a space like "_hey". No spaces. | |
winsound.PlaySound(" hey.wav", winsound.SND_FILENAME) | |
# You hear the WINDOWS ERROR SOUND PING! because YOUR file is actually an .mp3 and not a .wav | |
# winsound doesn't do mp3 files. Use an online .mp3 to .wav converter. Google it. | |
# Do I need the .wav at the end of the file? No. Both of these will work with winsound. | |
winsound.PlaySound("hey", winsound.SND_FILENAME) | |
winsound.PlaySound("hey.wav", winsound.SND_FILENAME) | |
#If it's on your C drive you can even use: | |
winsound.PlaySound("C:hey", winsound.SND_FILENAME) | |
######################################################################## | |
# "No module" errors | |
######################################################################## | |
ModuleNotFoundError: No module named 'windsound' | |
# It's winsound not windsound | |
ModuleNotFoundError: No module named 'Winsound' | |
# It's winsound not Winsound. Loose the capital "W". | |
######################################################################## | |
# HOW DO I USE A SOUND FILE THAT IS NOT IN THE SAME FOLDER AS MY PYTHON FILE??? | |
######################################################################## | |
# You might be clever and try | |
winsound.PlaySound("C:\Users\The Twins Tower\Desktop\wavs\Pythonwavs\chick.wav", winsound.SND_FILENAME) | |
#You'd be very close! But you'll get an error that looks like this: | |
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape | |
#the trick is to use DOUBLE BACK SLASHES! This will work. | |
winsound.PlaySound("C:\\Users\\The Twins Tower\\Desktop\\wavs\\Pythonwavs\\chick.wav", winsound.SND_FILENAME) |
I tried it with winsound.PlaySound('Test.wav', winsound.SND_FILENAME ), but when I run the code I only hear the windows background sound and not the actual sound.
but this trick worked
winsound.PlaySound("C:\Users\The Twins Tower\Desktop\wavs\Pythonwavs\chick.wav", winsound.SND_FILENAME)
you are the best
Thank you so much for this!!!! This solved my problem with winsound!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this 👍