0

我想要一个可以在播放声音文件的 Windows 机器上在后台运行的 Python 脚本。

我有两个不同的脚本,它们仅在我将代码复制并粘贴到 Python 解释器中时才起作用。声音将成功播放。

如果我改为cmd输入python run.py,脚本将以相同的标准运行,但不会播放声音。

# can only hear sound when this code is run in interpreter
from pygame import mixer
mixer.init()
mixer.music.load("C:\\Sound.mp3")
mixer.music.play()
# can only hear sound when this code is run in interpreter
import winsound
winsound.PlaySound("C:\\Sound.wav", winsound.SND_ASYNC)

如何解决这个问题?

4

0 回答 0