Fix cli bugs

- Add keycode 127 as backspace
 - Run tts in another thread to suppress output
pull/844/head
Matthew D. Scholefield 2017-06-15 11:43:08 -05:00 committed by Steve Penrod
parent 8e17fe3fd4
commit fc3ede120c
1 changed files with 29 additions and 14 deletions

View File

@ -248,30 +248,45 @@ def rebuild_filtered_log():
############################################################################## ##############################################################################
# Capturing output from Mycroft # Capturing output from Mycroft
def handle_speak(event): tts_threads = []
global chat
def start_tts(utterance):
"""
Begin speaking in another thread to redirect output
Otherwise, the CLI get's polluted with text to speech debug
"""
global tts global tts
mutex.acquire() mutex.acquire()
if not bQuiet: if not bQuiet:
ws.emit(Message("recognizer_loop:audio_output_start")) ws.emit(Message("recognizer_loop:audio_output_start"))
try: try:
utterance = event.data.get('utterance') if not tts:
if bSimple: tts = TTSFactory.create()
print(">> " + utterance) tts.init(ws)
else: tts.execute(utterance)
chat.append(">> " + utterance)
draw_screen()
if not bQuiet:
if not tts:
tts = TTSFactory.create()
tts.init(ws)
tts.execute(utterance)
finally: finally:
mutex.release() mutex.release()
if not bQuiet: if not bQuiet:
ws.emit(Message("recognizer_loop:audio_output_end")) ws.emit(Message("recognizer_loop:audio_output_end"))
def handle_speak(event):
global chat
global tts_threads
utterance = event.data.get('utterance')
if bSimple:
print(">> " + utterance)
else:
chat.append(">> " + utterance)
draw_screen()
if not bQuiet:
t = Thread(start_tts, utterance)
t.start()
tts_threads.append(t)
def connect(): def connect():
# Once the websocket has connected, just watch it for speak events # Once the websocket has connected, just watch it for speak events
ws.run_forever() ws.run_forever()
@ -749,7 +764,7 @@ def main(stdscr):
# resizeterm() causes another curses.KEY_RESIZE, so # resizeterm() causes another curses.KEY_RESIZE, so
# we need to capture that to prevent a loop of resizes # we need to capture that to prevent a loop of resizes
c = scr.getch() c = scr.getch()
elif c == curses.KEY_BACKSPACE: elif c == curses.KEY_BACKSPACE or c == 127:
# Backspace to erase a character in the utterance # Backspace to erase a character in the utterance
line = line[:-1] line = line[:-1]
elif curses.ascii.isascii(c): elif curses.ascii.isascii(c):