如何使用Python播放声音

2024-09-26 18:07:15 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我有两个不同的脚本,只有当我将代码复制并粘贴到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)

如何解决这个问题


Tags: runin脚本声音onlyiscodethis

热门问题