-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.py
54 lines (44 loc) · 1.54 KB
/
stack.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
from random import randint
from time import sleep
class PromptStack:
_on_speak = None
_on_listen = None
_history = []
_phrase = ''
last = ''
_ssml = ''
def __init__(self, invoker, recognize, prompts_dict) -> None:
self._invoker = invoker
self._recognize = recognize
self.PROMPTS = prompts_dict
def push(self, *actions) -> None:
self.add_history(*actions)
for self.action in actions:
self.check_in_prompts()
self.add_in_phrase()
def add_history(self, *actions):
self._history.append(actions)
def check_in_prompts(self) -> None:
if self.action in self.PROMPTS:
prompt_list = self.PROMPTS[self.action]
self.action = prompt_list[randint(0, len(prompt_list)-1)]
def add_in_phrase(self) -> None:
self._phrase += str(self.action or ' ') + '<break time="250ms"/> '
def say(self, *actions) -> None:
self.push(*actions)
self._invoker.set_on_speak(self._phrase)
self._invoker.do_speak()
self.last = self._phrase
self._phrase = ''
def listen(self) -> None:
self._invoker.set_on_listen(self._recognize)
self._invoker.do_listen()
def say_and_listen(self, *actions) -> None:
self.push(*actions)
self._invoker.set_on_speak(self._phrase)
self._invoker.do_speak()
# sleep(0.00001)
self._invoker.set_on_listen(self._recognize)
self._invoker.do_listen()
self.last = self._phrase
self._phrase = ''