Python winsound, ASYNC flag not working?

十年热恋 提交于 2020-01-24 20:40:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!