-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaltspeak.py
50 lines (33 loc) · 1.14 KB
/
altspeak.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import win32com.client
SPEAKING_SPEED = 300
class Speaker():
# def __init__(self, parent):
# self.parent = parent
def __init__(self):
self.tts = win32com.client.Dispatch('SAPI.Spvoice')
# self.print_voices()
self.set_voice(2)
self.set_speed(SPEAKING_SPEED)
self.tell_speed()
def set_voice(self, voice_number):
voices = self.tts.GetVoices()
self.tts.Voice = voices.Item(voice_number)
def print_voices(self):
voices = self.tts.GetVoices()
for voice in voices:
print(voice.GetDescription())
print(f"Current voice: {self.tts.Voice.GetDescription()}")
def set_speed(self, speed):
self.tts.Rate = speed
def tell_speed(self):
self.speak(f"I'm speaking {self.tts.Rate} words per minute.")
def speak(self, text):
self.tts.Speak(text)
# self.parent.file.log(f"A: {text}")
# class ContextEvents():
# def OnWord():
# print("the word event occured")
# # Work with Result
speaker = Speaker()
# event = win32com.client.WithEvents(speaker, ContextEvents)
speaker.speak("Just testing the voice")