问题
I'm using python 3.5 and I'm trying to play a sound while continuing right away with my script; according to https://docs.python.org/3.5/library/winsound.html the flag "winsound.SND_ASYNC" should be the way to go. However the following doesn't produce any sound:
import winsound
winsound.PlaySound('C:/Users/Bob/Sounds/sound.wav', winsound.SND_ASYNC)
Interesting enough if I change the flag to "winsound.SND_FILENAME the sound is played:
import winsound
winsound.PlaySound('C:/Users/Bob/Sounds/sound.wav', winsound.SND_FILENAME)
Any ideas why the async flag doesn't work?
回答1:
According to the docs,
The sound parameter may be a filename, audio data as a string, or None. Its interpretation depends on the value of flags, which can be a bitwise ORed combination of the constants described below
Something like follows:
import winsound
winsound.PlaySound('C:/Users/Bob/Sounds/sound.wav', winsound.SND_FILENAME | winsound.SND_ASYNC)
来源:https://stackoverflow.com/questions/45128232/python-winsound-async-flag-not-working