-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtts.py
56 lines (46 loc) · 1.34 KB
/
tts.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
51
52
53
import subprocess
import threading
import time
import wordninja
import os
class Tts:
code = [["A", "B", "C", "D", "E"],
["F", "G", "H", "I", "J"],
["L", "M", "N", "O", "P"],
["Q", "R", "S", "T", "U"],
["V", "W", "X", "Y", "Z"]]
def __init__(self):
self.sentence = ""
self.current_row = -1
def select_row(self, key):
self.current_row = key
self.speak(self.code[key][0], 110)
self.speak(" too ")
self.speak(self.code[key][4], 110)
def select_letter(self, key):
letter = self.code[self.current_row][key]
self.current_row = -1
self.sentence += letter
self.speak(letter)
def play_sentence(self):
sentence = " ".join(wordninja.split(self.sentence))
self.speak(sentence)
self.sentence = ""
self.current_row = -1
'''
0-4 = rows/letters
5 = speak sentence
6 = go back
'''
def handle_action(self, key):
if key == 5:
self.play_sentence()
elif key == 6:
pass
else:
if self.current_row == -1:
self.select_row(key)
else:
self.select_letter(key)
def speak(self, sentence, wpm=60):
subprocess.run(['espeak', '-s' + str(wpm), sentence])