From 46299d2dac92a2558c11a0925688842bc596904f Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 25 Jan 2019 11:59:03 +0100 Subject: [PATCH] Change language --- hugvey/central_command.py | 14 ++++++++++---- hugvey/panopticon.py | 16 ++++++++++++---- hugvey/voice/google.py | 1 + www/index.html | 21 ++++++++++++++------- www/js/hugvey_console.js | 22 ++++++++++++++++------ 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/hugvey/central_command.py b/hugvey/central_command.py index cdf2524..a8d904f 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -338,18 +338,24 @@ class HugveyState(object): self.restart() if event['event'] == 'resume': self.resume() + + if event['event'] == 'change_language': + self.setLanguage(event['lang_code']) self.eventQueue = None def setLanguage(self, language_code): if language_code not in self.command.languages: raise Exception("Invalid language {}".format(language_code)) - + + self.logger.info(f"set language: {language_code}") self.language_code = language_code self.google.setLanguage(language_code) + + self.restart() - self.story.reset() - self.story.setStoryData(self.command.languages[language_code]) +# self.story.reset() +# self.story.setStoryData(self.command.languages[language_code]) def pause(self): self.logger.info('Pause') @@ -372,7 +378,7 @@ class HugveyState(object): def restart(self): self.logger.info('Restart') if self.story: - self.story.reset() + self.story.stop() self.resume() self.isRunning.set() diff --git a/hugvey/panopticon.py b/hugvey/panopticon.py index 6a9631c..f280a1e 100644 --- a/hugvey/panopticon.py +++ b/hugvey/panopticon.py @@ -45,14 +45,19 @@ def getWebSocketHandler(central_command): msg = json.loads(message) if msg['action'] == 'init': self.msgInit() - if msg['action'] == 'get_status': + elif msg['action'] == 'get_status': self.msgStatus() - if msg['action'] == 'resume': + elif msg['action'] == 'resume': self.msgResume(msg['hugvey']) - if msg['action'] == 'pause': + elif msg['action'] == 'pause': self.msgPause(msg['hugvey']) - if msg['action'] == 'restart': + elif msg['action'] == 'restart': self.msgRestart(msg['hugvey']) + elif msg['action'] == 'change_language': + self.msgChangeLanguage(msg['hugvey'], msg['lang_code']) + else: + self.send({'alert': 'Unknown request: {}'.format(message)}) + logger.warn('Unknown request: {}'.format(message)) except Exception as e: self.send({'alert': 'Invalid request: {}'.format(e)}) @@ -88,6 +93,9 @@ def getWebSocketHandler(central_command): def msgRestart(self, hv_id): central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'restart'}) + + def msgChangeLanguage(self, hv_id, lang_code): + central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_language', 'lang_code': lang_code}) return WebSocketHandler diff --git a/hugvey/voice/google.py b/hugvey/voice/google.py index 21003f5..c925e5e 100644 --- a/hugvey/voice/google.py +++ b/hugvey/voice/google.py @@ -69,6 +69,7 @@ class GoogleVoiceClient(object): while not self.toBeShutdown: try: self.isRunning.wait() + logger.info("Starting Google Voice") self.speech_client = speech.SpeechClient() config = types.RecognitionConfig( diff --git a/www/index.html b/www/index.html index b15474e..2b2360d 100644 --- a/www/index.html +++ b/www/index.html @@ -33,7 +33,14 @@ {{ hv.id }}
{{ hv.status }}
-
+
+ {{ hv.language }}
{{timer(hv, 'finished')}}
@@ -43,14 +50,14 @@ {{c}}
- - {{ hv.msg }} + + {{ hv.msg }}
-
Pause
-
Resume
-
Restart
- +
Pause
+
Resume
+
Restart
+
diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index 63c30b8..a622424 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -22,14 +22,21 @@ class Panopticon { loadNarrative: function( code, file ) { return panopticon.loadNarrative( code, file ); }, - pause: function(hv_id) { - return panopticon.pause(hv_id); + pause: function(hv) { + hv.status = "loading"; + return panopticon.pause(hv.id); }, - resume: function(hv_id) { - return panopticon.resume(hv_id); + resume: function(hv) { + hv.status = "loading"; + return panopticon.resume(hv.id); }, - restart: function(hv_id) { - return panopticon.restart(hv_id); + restart: function(hv) { + hv.status = "loading"; + return panopticon.restart(hv.id); + }, + change_lang: function(hv, lang_code) { + hv.status = "loading"; + return panopticon.change_language(hv.id, lang_code); } } } ); @@ -127,6 +134,9 @@ class Panopticon { restart( hv_id ) { this.send( { action: 'restart', hugvey: hv_id } ) } + change_language( hv_id, lang_code ) { + this.send( { action: 'change_language', hugvey: hv_id, lang_code: lang_code } ); + } }