-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
90 lines (69 loc) · 1.84 KB
/
test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pyttsx as pyttsx
import time
class Translator():
def __init__(self):
self.line = 0
self.listeners = []
def __add__(self, k):
self.line = self.line + k
for listener in self.listeners:
listener._call()#textFrame.event_generate('<<myEvent>>')
def add_listener(self, listener):
self.listeners.append(listener)
pause = False
i = 0
# textObj = Translator()
def start_engine(engine=None):
if engine is None:
engine = pyttsx.init()
engine.setProperty("rate", 170)
if not engine._inLoop:
engine.startLoop(False)
engine.say("Ready")
engine.iterate()
# engine.endLoop()
return(engine)
def say_text(engine, text):
'''
for seq in text:
if not pause:
engine.say(seq)
time.sleep(3)
else:
print("pause")
return(0)
return(0)
'''
global i
#i = 0
def onEnd(name, completed):
#print(("finishing",name,engine.isBusy()))
global i
global pause
#global textObj
i = i+1
#print(i)
if i < len(text) and not pause:
#textObj+1
try:
engine.say(text[i])
except:
print("exception i")
else:
engine.disconnect(cn)
# if not pause then text ended
if not pause:
i = 0
else:
# play from one sequence back
if i>0:
i = i-1
print("disconnected first")
cn = engine.connect("finished-utterance", onEnd)
engine.say(text[i])
def stop_engine(engine):
engine.endLoop()
engine.stop()
#def test():
# engine.proxy.startLoop(True)
#engine.proxy._driver.__init__(engine.proxy)