简体   繁体   English

树莓派上的 Python3 程序不播放声音,即使音频可以正常工作

[英]Python3 program on raspberry pi doesn't play sound, even though audio works otherwise

I am trying to play a sound with the playsound module on python3 with my raspberry pi 3 model B+.我正在尝试使用我的树莓派 3 型号 B+ 在 python3 上使用 playsound 模块播放声音。 I use gTTS to save a tts file and use the playsound module to play the sound.我使用 gTTS 保存 tts 文件并使用 playsound 模块播放声音。 But, for some reason the code completes with no errors and the audio won't play.但是,由于某种原因,代码完成时没有错误,音频也不会播放。

I've tried messing with sound options in the preferences, but the audio works fine if I want to play the file manually, for some reason it just does not work through the python code.我试过在首选项中弄乱声音选项,但如果我想手动播放文件,音频工作正常,由于某种原因,它不能通过 python 代码工作。

from gtts import gTTS
from playsound import playsound

morning = gTTS(text="Good morning the time is now 8 AM")
# morning.save("morning.wav")
playsound("morning.wav")

I also faced same problem.我也面临同样的问题。 And believe no forum on the internet gave answer to this question.并且相信互联网上没有论坛给出了这个问题的答案。 Then I tried pygame mixer pre installed in the pi.然后我尝试了在 pi 中预先安装的 pygame 混合器。 I can't tell you the full process of using it.我不能告诉你使用它的完整过程。 Google it and you will find a way to play the audio with pygame.谷歌一下,你会找到一种用 pygame 播放音频的方法。 I hope this method helps you.我希望这个方法对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM