Try better timing for replyContains timings
This commit is contained in:
parent
837e19d5e7
commit
88ebcda2e3
2 changed files with 15 additions and 13 deletions
|
@ -20,14 +20,14 @@ from hugvey.communication import LOG_BS
|
|||
import audioop
|
||||
|
||||
mainLogger = logging.getLogger("hugvey")
|
||||
logger = mainLogger.getChild("speech")
|
||||
logger = mainLogger.getChild("google")
|
||||
|
||||
class RequireRestart(Exception):
|
||||
pass
|
||||
|
||||
class GoogleVoiceClient(object):
|
||||
def __init__(self, hugvey, src_rate, credential_file, language_code = "en_GB"):
|
||||
self.logger = mainLogger.getChild(f"{hugvey.id}").getChild('speech')
|
||||
self.logger = mainLogger.getChild(f"{hugvey.id}").getChild('google')
|
||||
self.src_rate = src_rate
|
||||
self.hugvey = hugvey
|
||||
self.language_code = language_code
|
||||
|
@ -187,13 +187,13 @@ class GoogleVoiceClient(object):
|
|||
self.subsequentMutedFrames += 1
|
||||
# self.logger.debug("Muted")
|
||||
if self.subsequentMutedFrames > 4 and self.isRunning.is_set():
|
||||
self.logger.warn("Pause muted stream!")
|
||||
self.logger.info("Pause muted stream!")
|
||||
self.pause()
|
||||
return
|
||||
|
||||
# self.logger.debug("We have mic!")
|
||||
if not self.isRunning.is_set():
|
||||
self.logger.warn("Resume voice")
|
||||
self.logger.info("Resume voice")
|
||||
self.resume()
|
||||
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ class Utterance(object):
|
|||
self.startTime = startTime
|
||||
self.endTime = None
|
||||
self.text = ""
|
||||
self.lastUpdate = startTime
|
||||
self.lastUpdateTime = startTime
|
||||
|
||||
def setText(self, text, now):
|
||||
self.text = text
|
||||
self.lastUpdate = now
|
||||
self.lastUpdateTime = now
|
||||
|
||||
def setFinished(self, endTime):
|
||||
self.endTime = endTime
|
||||
|
@ -193,7 +193,7 @@ class Reply(object):
|
|||
return u
|
||||
|
||||
now = self.forMessage.story.timer.getElapsed()
|
||||
diff = now - u.lastUpdate
|
||||
diff = now - u.lastUpdateTime
|
||||
if diff > 5: # time in seconds to force silence in utterance
|
||||
# useful for eg. 'hello', or 'no'
|
||||
self.forMessage.story.logger.warn(
|
||||
|
@ -344,9 +344,6 @@ class Condition(object):
|
|||
return True
|
||||
# TODO: implement 'instant match' -> don't wait for isFinished()
|
||||
|
||||
if r.isSpeaking():
|
||||
story.logger.log(LOG_BS, f"is speaking: {r.getLastUtterance().text} - {r.getLastUtterance().startTime}")
|
||||
return False
|
||||
|
||||
# print(self.vars)
|
||||
# either there's a match, or nothing to match at all
|
||||
|
@ -355,17 +352,22 @@ class Condition(object):
|
|||
story.logger.debug("not finished playback yet")
|
||||
return False
|
||||
# time between finishing playback and ending of speaking:
|
||||
replyDuration = r.getLastUtterance().endTime - story.lastMsgFinishTime
|
||||
replyDuration = r.getLastUtterance().lastUpdateTime - story.lastMsgFinishTime # using lastUpdateTime instead of endTime
|
||||
delays = sorted(self.vars['delays'], key=lambda k: float(k['minReplyDuration']), reverse=True)
|
||||
for delay in delays:
|
||||
if replyDuration > float(delay['minReplyDuration']):
|
||||
timeSinceReply = story.timer.getElapsed() - r.getLastUtterance().endTime
|
||||
timeSinceReply = story.timer.getElapsed() - r.getLastUtterance().lastUpdateTime
|
||||
story.logger.log(LOG_BS, f"check delay duration is now {replyDuration}, already waiting for {timeSinceReply}, have to wait {delay['waitTime']}")
|
||||
if timeSinceReply > float(delay['waitTime']):
|
||||
return True
|
||||
break # don't check other delays
|
||||
# wait for delay to match
|
||||
story.logger.debug("Wait for it...")
|
||||
story.logger.log(LOG_BS, "Wait for it...")
|
||||
return False
|
||||
|
||||
# If there is a delay, it takes precedence of isSpeaking, since google does not always give an is_finished on short utterances (eg. "hello" or "no")
|
||||
if r.isSpeaking():
|
||||
story.logger.log(LOG_BS, f"is speaking: {r.getLastUtterance().text} - {r.getLastUtterance().startTime}")
|
||||
return False
|
||||
|
||||
# There is a match and no delay say, person finished speaking. Go ahead sir!
|
||||
|
|
Loading…
Reference in a new issue