forked from AntonyRusso/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tts_pyttsx3.py
36 lines (29 loc) · 754 Bytes
/
tts_pyttsx3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pyttsx3
# initialize Text-to-speech engine
engine = pyttsx3.init()
# convert this text to speech
text = "Python is a great programming language"
engine.say(text)
# play the speech
engine.runAndWait()
# get details of speaking rate
rate = engine.getProperty("rate")
print(rate)
# setting new voice rate (faster)
engine.setProperty("rate", 300)
engine.say(text)
engine.runAndWait()
# slower
engine.setProperty("rate", 100)
engine.say(text)
engine.runAndWait()
# get details of all voices available
voices = engine.getProperty("voices")
print(voices)
# set another voice
engine.setProperty("voice", voices[1].id)
engine.say(text)
engine.runAndWait()
# saving speech audio into a file
engine.save_to_file(text, "python.mp3")
engine.runAndWait()