To run the py code below you need to install pyttsx3 first.
pip install pyttsx3
Example :
xxxxxxxxxx
import pyttsx3
import datetime
engine = pyttsx3.init()
​
#Rate
rate = engine.getProperty('rate')
​
engine.setProperty("rate", 150)
​
volume = engine.getProperty('volume')
print("volume is {0}".format(volume))
​
engine.setProperty("volume",0.9)
voices = engine.getProperty("voices")
​
# Male voice : voices[0].id
# Female voice : voices[1].id
​
engine.setProperty("voice", voices[0].id)
src = "your_source_file.txt"
content = open(src).read()
now = datetime.datetime.now().strftime('%Y%m-%d%H-%M%S-')
engine.save_to_file(content, "your_audio_folder/"+now+".mp3")
#run
engine.runAndWait()