How to convert text to speech in python 3.5 on win

2020-03-25 11:26发布

问题:

I tried espeak but didn't succeed and some functionalities only supported in python 2.

回答1:

Have you tried using gTTS?

The syntax for using it in Python 3.x is as follows:

from gtts import gTTS
my_tts = "Text you want to process"
tts = gTTS(text=my_tts, lang='en')
tts.save("Absolute/path/to/file.mp3")

Here is the github repo of gTTS.



回答2:

For offline use: Direct use SAPI [Windows]

Following code will help for demo...

import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") speaker.Speak("Jumpman Jumpman Jumpman Them boys up to something!")