我怎样才能 运行 编码一段时间?

How can I run code for a certain amount of time?

我想使用 winsound 的 winsound.PlaySound 功能播放声音(来自 wav 文件)。我知道 winsound.Beep 允许我以毫秒为单位指定时间,但我如何使用 winsound.PlaySound 实现该行为?

我尝试使用time.sleep功能,但那只是延迟功能,并没有指定时间量。

如有任何帮助,我们将不胜感激。

创建一个线程来播放声音,启动它。创建一个休眠时间适当并具有第一个线程句柄的线程。让第二个线程在睡眠结束时终止第一个线程。