From d530980b0edf6467e3a8cd7b071021b94842afdd Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sat, 27 Apr 2019 12:13:34 +0200 Subject: [PATCH] Begin panopticon web interface and fix setLanguage() with new controls --- hugvey/central_command.py | 4 +- hugvey/speech/google.py | 17 +++++---- hugvey/story.py | 2 +- www/index.html | 4 +- www/js/hugvey_console.js | 30 ++++++++++++--- www/panopticon.html | 80 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 17 deletions(-) create mode 100644 www/panopticon.html diff --git a/hugvey/central_command.py b/hugvey/central_command.py index e623cef..17cd9cb 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -557,7 +557,9 @@ class HugveyState(object): self.logger.info(f"set language: {language_code}") self.language_code = language_code - self.google.setLanguage(language_code) + + if self.google: + self.google.setLanguage(language_code) if self.isRunning.is_set(): self.restart() diff --git a/hugvey/speech/google.py b/hugvey/speech/google.py index f4bd782..fe5d488 100644 --- a/hugvey/speech/google.py +++ b/hugvey/speech/google.py @@ -78,22 +78,25 @@ class GoogleVoiceClient(object): self.logger.info("Change language from {} to {}".format(self.language_code, language_code)) self.language_code = language_code + self.isRunning.clear() self.restart = True def run(self): self.isRunning.set() + # Leave this here to avoid "Too many files open" errors. self.speech_client = speech.SpeechClient() - config = types.RecognitionConfig( - encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, - sample_rate_hertz=self.src_rate, - language_code=self.language_code) - self.streaming_config = types.StreamingRecognitionConfig( - config=config, - interim_results=True) while not self.toBeShutdown: try: + config = types.RecognitionConfig( + encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, + sample_rate_hertz=self.src_rate, + language_code=self.language_code) + self.streaming_config = types.StreamingRecognitionConfig( + config=config, + interim_results=True) + self.logger.log(LOG_BS,"wait for Google Voice") if not self.isRunning.wait(timeout=1): continue # re-ceck toBeShutdown diff --git a/hugvey/story.py b/hugvey/story.py index 5e487cd..cee4b90 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -1226,7 +1226,7 @@ class Story(object): """ self.finish() #stop google etc: - self.hugvey.awaiting() + self.hugvey.available() def finish(self): """ diff --git a/www/index.html b/www/index.html index 1388dbc..8df8f00 100644 --- a/www/index.html +++ b/www/index.html @@ -1,6 +1,6 @@ -Pillow Talk Control Interface +Pillow Talk Editor @@ -12,7 +12,7 @@ - +
diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index d308b7e..463db90 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -3,6 +3,7 @@ var panopticon; class Panopticon { constructor() { console.log( "Init panopticon" ); + this.hasGraph = document.body.classList.contains('editor'); this.languages = [] // this.selectedHugvey = null; this.hugveys = new Vue( { @@ -21,8 +22,11 @@ class Panopticon { return panopticon.stringToHHMMSS( hugvey[property] ); }, loadNarrative: function( code, file ) { - panopticon.hugveys.selectedId = null; - return panopticon.loadNarrative( code, file ); + panopticon.hugveys.selectedId = null; + + if(panopticon.hasGraph) { + return panopticon.loadNarrative( code, file ); + } }, block: function(hv) { hv.status = "loading"; @@ -62,7 +66,10 @@ class Panopticon { this.socket = new ReconnectingWebSocket( "ws://localhost:8888/ws", null, { debug: false, reconnectInterval: 3000 } ); - this.graph = new Graph(); + + if(this.hasGraph) { + this.graph = new Graph(); + } this.socket.addEventListener( 'open', ( e ) => { @@ -78,6 +85,11 @@ class Panopticon { console.log( 'Closed connection' ); } ); this.socket.addEventListener( 'message', ( e ) => { + if(e.data == 'hello!') { + console.log("Websocket connected") + return; + } + let msg = JSON.parse( e.data ); if ( typeof msg['alert'] !== 'undefined' ) { alert( msg['alert'] ); @@ -113,11 +125,17 @@ class Panopticon { if(this.hugveys.selectedId) { hv = this.getHugvey(this.hugveys.selectedId); - if(hv.language && this.graph.language_code != hv.language) { - this.loadNarrative(hv.language); + + if(this.hasGraph) { + if(hv.language && this.graph.language_code != hv.language) { + this.loadNarrative(hv.language); + } } } - this.graph.updateHugveyStatus(hv); + + if(this.hasGraph) { + this.graph.updateHugveyStatus(hv); + } } getHugvey(id) { diff --git a/www/panopticon.html b/www/panopticon.html new file mode 100644 index 0000000..1c4a56c --- /dev/null +++ b/www/panopticon.html @@ -0,0 +1,80 @@ + + +Pillow Talk Control Interface + + + + + + + + + + + + +
+
+
+
+
Uptime
+
{{uptime}}
+
+ +
    +
  • {{lang.code}}
  • +
+ +
+
+

+ {{ hv.id }} +

+
{{ hv.status }}
+
+ + {{ hv.language }} + +
+
+ + {{c}} +
+
+ + {{ hv.msg }} +
+
+ + {{ timer(hv, 'duration') }} +
+
+
Unblock
+
Block
+
Start
+
Finish
+
Pause
+
Resume
+
+
+
+
+ +
+
+ + + \ No newline at end of file