1import pyttsx3
2engine = pyttsx3.init()
3engine.say("I will speak this text")
4engine.runAndWait()
5
1import pyttsx3
2engine = pyttsx3.init() # object creation
3
4""" RATE"""
5rate = engine.getProperty('rate') # getting details of current speaking rate
6print (rate) #printing current voice rate
7engine.setProperty('rate', 125) # setting up new voice rate
8
9
10"""VOLUME"""
11volume = engine.getProperty('volume') #getting to know current volume level (min=0 and max=1)
12print (volume) #printing current volume level
13engine.setProperty('volume',1.0) # setting up volume level between 0 and 1
14
15"""VOICE"""
16voices = engine.getProperty('voices') #getting details of current voice
17#engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male
18engine.setProperty('voice', voices[1].id) #changing index, changes voices. 1 for female
19
20engine.say("Hello World!")
21engine.say('My current speaking rate is ' + str(rate))
22engine.runAndWait()
23engine.stop()
24
25"""Saving Voice to a file"""
26# On linux make sure that 'espeak' and 'ffmpeg' are installed
27engine.save_to_file('Hello World', 'test.mp3')
28engine.runAndWait()
29