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.
This commit is contained in:
Ruben van de Ven 2019-05-14 18:18:42 +02:00
parent 4efd8c2e09
commit 78625259c9
3 changed files with 21 additions and 9 deletions

View file

@ -518,7 +518,7 @@ class HugveyState(object):
""" """
Put event in both the event loop for the story as well as the Hugvey State handler 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) self.eventQueue.put_nowait(msg)
# connection events don't need to go to the story # connection events don't need to go to the story

View file

@ -172,14 +172,16 @@ class GoogleVoiceClient(object):
except Exception as e: except Exception as e:
self.logger.critical(f"Crashed Google Voice: {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. # make sure we always send a 'final' transcript.
if self.lastNonFinalTranscript is not None: # if self.lastNonFinalTranscript is not None:
msg = { # msg = {
"event": "speech", # "event": "speech",
"is_final": True, # "is_final": True,
"transcript": self.lastNonFinalTranscript.strip(), # "transcript": self.lastNonFinalTranscript.strip(),
} # }
self.hugvey.queueEvent(msg) # self.hugvey.queueEvent(msg)
self.logger.warn("Stop google run()") # finish means wrapping of hugvey#3v thread self.logger.warn("Stop google run()") # finish means wrapping of hugvey#3v thread
# time.sleep(1) # time.sleep(1)

View file

@ -35,6 +35,9 @@ class Utterance(object):
self.text = text self.text = text
self.lastUpdateTime = now self.lastUpdateTime = now
def hasText(self):
return len(self.text) > 0
def setFinished(self, endTime): def setFinished(self, endTime):
self.endTime = endTime self.endTime = endTime
@ -1349,7 +1352,14 @@ class Story(object):
now = self.timer.getElapsed() now = self.timer.getElapsed()
utterance = self.currentReply.getActiveUtterance(now) 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.hugvey.eventLogger.info("speaking: content {} \"{}\"".format(id(utterance), e['transcript']))
self.timer.setMark('last_speech') self.timer.setMark('last_speech')