-
Notifications
You must be signed in to change notification settings - Fork 1
/
audio_ui.py
43 lines (36 loc) · 1.19 KB
/
audio_ui.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
from Tkinter import StringVar
import speechtest as speech
class AudioUI:
class __AudioUI:
def __init__(self, top, text):
self.text = text
self.top = top
def __update(self, s):
self.clear()
got_text = self.text.get()
self.text.set(got_text + s)
self.top.update_idletasks()
def clear(self):
self.text.set('')
self.top.update_idletasks()
def get_text(self):
return self.text.get()
def listen(self):
user_input = None
while not user_input:
user_input = speech.speechrec()
print user_input
self.__update('You: ' + user_input + '\n\n')
return user_input
def respond(self, s):
self.__update('Sparky: ' + s + '\n\n')
self.top.update_idletasks()
speech.speech_play_test(str)
instance = None
def __init__(self, text, top):
if not AudioUI.instance:
AudioUI.instance = AudioUI.__AudioUI(text,top)
else:
AudioUI.instance.text = text
def __getattr__(self, name):
return getattr(self.instance, name)