如何跳过等待 winsound 结束?

huangapple go评论65阅读模式
英文:

How to skip waiting for winsound to end?

问题

winsound播放时,Python会等待音频结束。我的目标是通过winsound播放声音,同时在声音仍在播放时继续执行。是否有解决方法?

英文:

Every time winsound is played python waits until audio ends. My goal is to play sound via winsound and continue while sound is still playing. Is there a workaround?

答案1

得分: 2

使用多个线程,如 @xihtyM 所提到的,是不必要的。文档 描述了方法 winsound.PlaySound 的几个标志。

你要寻找的是:

import winsound

winsound.PlaySound('*' , winsound.SND_ASYNC)

这个标志让方法立即返回。

英文:

Using multiple threads as @xihtyM mentions is not necessary. The documentation describes several flags for the method winsound.PlaySound.

The one you are looking for is:

import winsound

winsound.PlaySound('*', windsound.SND_ASYNC)

this flag let the method return immediately.

huangapple
  • 本文由 发表于 2023年3月12日 06:31:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75709970.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定