Why are you playing the Windows error sound instead of the specified file?

Asked

Viewed 134 times

0

import winsound


winsound.PlaySound('C:/Users/Computador/Music/Action!/som1.wav', winsound.SND_ASYNC)

When I run this script the file is not touched som1.wav, but rather the Windows error sound. Why?

  • That exclamation point "!" composes the URL?

  • 1

    Great chance to be the wrong file path. Try adding the flag winsound.SND_NODEFAULT - This flag determines that if you do not find the file, it is not to put the default sound in place. And make sure that your som1.wav is not the same as Windows...

  • 1

    Gave ''Failed to play sound'' with ''winsound.SND_NODEFAULT''

  • So we already know that the problem is in your audio. Could you confirm if the exclamation is part of the path of your file?

  • Yes, she is part

  • And it is allowed to have this character in the path of a file on Windows?

  • Even without the ''! '

  • To remove the doubt, put the sound in the same folder of the application, to see if the problem is in the file or in the path

  • winsound.SND_FILENAME: The sound Parameter is the name of a WAV file. You wouldn’t have to use this flag?

  • I put in the same folder, I used the flag 'SND_FILENAME', I used another sound with mp3 format, but still plays the sound of windows

  • Tried to do all this with a same WAV file?

  • Yeah, I tried with the WAV

  • @Tortaamolante tries going by variable the path, as in this example

  • I managed to solve the problem, the script could not find the file and so played the default sound of windows, but I changed the flag and put another file and it worked.

  • Edit the answer with the troubleshooting if someone has the same problem ;)

  • All right, I put it :)

Show 11 more comments

1 answer

3


The problem was missing the flag SND_NODEFAULT and the directory was wrong.

import winsound

winsound.PlaySound('teste.wav', winsound.SND_FILENAME | winsound.SND_PURGE | winsound.SND_NODEFAULT)

I tested with mp3 files and it didn’t work, only with wav

  • is right - that’s what worked - the problem was just the file path and the lack of the SND_NODEFAULT. If the question is edited to include this, it is no longer a question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.