I am trying the gTTS (Google Text To Speach) function in python, saving the mp3 file works (the file is being saved and can be played).
Now I am trying to play the file directly with the below code, but it is throwing an error
Code:
import gtts
import pyglet
import os
import time
text = ("Hello World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = 'c:/test_voice.mp3'
obj.save(speech_filename)
print("Play sound...")
music = pyglet.media.load(speech_filename, streaming=False)
music.play
sleep.time(music.duration) #prevent from killing
os.remove(speech_filename) #remove temp file
Error:
Traceback (most recent call last): File "C:\python\text-to-speach.py", line 16, in music = pyglet.media.load(speech_filename, streaming=False)
File "C:\Python\lib\site-packages\pyglet\media\sources\loader.py", line 63, in load source = get_source_loader().load(filename, file)
File "C:\Python\lib\site-packages\pyglet\media\sources\loader.py", line 84, in load return WaveSource(filename, file)
File "C:\Python\lib\site-packages\pyglet\media\sources\riff.py", line 200, in init
'AVbin is required to decode compressed media') pyglet.media.sources.riff.WAVEFormatException: AVbin is required to decode compressed media