-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeaker.py
More file actions
31 lines (27 loc) · 790 Bytes
/
speaker.py
File metadata and controls
31 lines (27 loc) · 790 Bytes
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
"""
Speaker function --> speaks out a string
Dependencies:
- pyttsx3 // pip install pyttsx3
"""
import pyttsx3
class Speaker():
def __init__(self):
self.engine = pyttsx3.init()
self.change_voice(0)
self.change_voice_speed(230)
def speak_text(self, text):
print(f"CAIA >> {text}")
self.engine.say(text)
self.engine.runAndWait()
def change_voice(self, voice_number):
"""
Normal man voice = 0
Female voice = 41
"""
voices = self.engine.getProperty('voices')
self.engine.setProperty('voice', voices[voice_number].id)
def change_voice_speed(self, new_voice_rate):
"""
Default voice rate: 250
"""
self.engine.setProperty('rate', new_voice_rate)