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:
parent
4efd8c2e09
commit
78625259c9
3 changed files with 21 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
Loading…
Reference in a new issue