pythonpython-3.xraspberry-pigttspython-playsound

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 Python 3 with my raspberry pi 3 model B+. I use gTTS to save a tts file and use the playsound module to play the sound. 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:

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")

Solution

  • 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. 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. I hope this method helps you.