Reputation: 38
I use google-cloud text-to-speech API using python3 on linux.
The mp3 plays with os.startfile(), which opens a player.
Instead sending mp3 file & using mp3 player, I need to play audio through the browser.
I have tried:
I need advice on how to mimic what google has done in the browser as in the link here:
https://cloud.google.com/text-to-speech
Upvotes: 0
Views: 636
Reputation:
You can use the gTTS module to do text-to-speech in Python. And then you can use another module to play the sound using Python as well.
First install the following modules...
pip install gTTS
pip install playsound
Then you can do this...
from gtts import gTTS
import playsound
tts = gTTS('hello')
tts.save('hello.mp3')
playsound.playsound('hello.mp3')
This code should give you the same results as google in browser, because gtts uses the same API. If you have any problems you can comment and I will definitely reply :)
Upvotes: 1