From 78625259c936c2ee0b9654a9f1da1d0c99634da6 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Tue, 14 May 2019 18:18:42 +0200 Subject: [PATCH] Ignore the timing of all is_final messages completely It turns out google's is_final comes in at super arbitrary intervals. Sometimes 2 sec after finishing speaking. We take the final text but ignore its timing completely. --- hugvey/central_command.py | 2 +- hugvey/speech/google.py | 16 +++++++++------- hugvey/story.py | 12 +++++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/hugvey/central_command.py b/hugvey/central_command.py index dc9a2d2..40953d8 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -518,7 +518,7 @@ class HugveyState(object): """ Put event in both the event loop for the story as well as the Hugvey State handler """ - self.logger.debug(f"Queue event in hugvey loop: {msg}") +# self.logger.debug(f"Queue event in hugvey loop: {msg}") # a little less logging please :-) self.eventQueue.put_nowait(msg) # connection events don't need to go to the story diff --git a/hugvey/speech/google.py b/hugvey/speech/google.py index 007537d..7fa6343 100644 --- a/hugvey/speech/google.py +++ b/hugvey/speech/google.py @@ -172,14 +172,16 @@ class GoogleVoiceClient(object): except Exception as e: self.logger.critical(f"Crashed Google Voice: {e}") + # sending an extra message is deprecated since we ignore finals anyway # make sure we always send a 'final' transcript. - if self.lastNonFinalTranscript is not None: - msg = { - "event": "speech", - "is_final": True, - "transcript": self.lastNonFinalTranscript.strip(), - } - self.hugvey.queueEvent(msg) +# if self.lastNonFinalTranscript is not None: +# msg = { +# "event": "speech", +# "is_final": True, +# "transcript": self.lastNonFinalTranscript.strip(), +# } +# self.hugvey.queueEvent(msg) + self.logger.warn("Stop google run()") # finish means wrapping of hugvey#3v thread # time.sleep(1) diff --git a/hugvey/story.py b/hugvey/story.py index 689a27e..da7a3a4 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -34,6 +34,9 @@ class Utterance(object): def setText(self, text, now): self.text = text self.lastUpdateTime = now + + def hasText(self): + return len(self.text) > 0 def setFinished(self, endTime): self.endTime = endTime @@ -1349,7 +1352,14 @@ class Story(object): now = self.timer.getElapsed() utterance = self.currentReply.getActiveUtterance(now) - utterance.setText(e['transcript'], now) + # The 'is_final' from google sometimes comes 2 sec after finishing speaking + # therefore, we ignore the timing of this transcription if something has been said already + if e['is_final'] and utterance.hasText(): + self.logger.warning(f'ignore timing: {now} use {utterance.lastUpdateTime}') + utterance.setText(e['transcript'], utterance.lastUpdateTime) + else: + utterance.setText(e['transcript'], now) + self.hugvey.eventLogger.info("speaking: content {} \"{}\"".format(id(utterance), e['transcript'])) self.timer.setMark('last_speech')