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
|
import audioop
|
||||||
|
|
||||||
mainLogger = logging.getLogger("hugvey")
|
mainLogger = logging.getLogger("hugvey")
|
||||||
logger = mainLogger.getChild("speech")
|
logger = mainLogger.getChild("google")
|
||||||
|
|
||||||
class RequireRestart(Exception):
|
class RequireRestart(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class GoogleVoiceClient(object):
|
class GoogleVoiceClient(object):
|
||||||
def __init__(self, hugvey, src_rate, credential_file, language_code = "en_GB"):
|
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.src_rate = src_rate
|
||||||
self.hugvey = hugvey
|
self.hugvey = hugvey
|
||||||
self.language_code = language_code
|
self.language_code = language_code
|
||||||
|
@ -187,13 +187,13 @@ class GoogleVoiceClient(object):
|
||||||
self.subsequentMutedFrames += 1
|
self.subsequentMutedFrames += 1
|
||||||
# self.logger.debug("Muted")
|
# self.logger.debug("Muted")
|
||||||
if self.subsequentMutedFrames > 4 and self.isRunning.is_set():
|
if self.subsequentMutedFrames > 4 and self.isRunning.is_set():
|
||||||
self.logger.warn("Pause muted stream!")
|
self.logger.info("Pause muted stream!")
|
||||||
self.pause()
|
self.pause()
|
||||||
return
|
return
|
||||||
|
|
||||||
# self.logger.debug("We have mic!")
|
# self.logger.debug("We have mic!")
|
||||||
if not self.isRunning.is_set():
|
if not self.isRunning.is_set():
|
||||||
self.logger.warn("Resume voice")
|
self.logger.info("Resume voice")
|
||||||
self.resume()
|
self.resume()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ class Utterance(object):
|
||||||
self.startTime = startTime
|
self.startTime = startTime
|
||||||
self.endTime = None
|
self.endTime = None
|
||||||
self.text = ""
|
self.text = ""
|
||||||
self.lastUpdate = startTime
|
self.lastUpdateTime = startTime
|
||||||
|
|
||||||
def setText(self, text, now):
|
def setText(self, text, now):
|
||||||
self.text = text
|
self.text = text
|
||||||
self.lastUpdate = now
|
self.lastUpdateTime = now
|
||||||
|
|
||||||
def setFinished(self, endTime):
|
def setFinished(self, endTime):
|
||||||
self.endTime = endTime
|
self.endTime = endTime
|
||||||
|
@ -193,7 +193,7 @@ class Reply(object):
|
||||||
return u
|
return u
|
||||||
|
|
||||||
now = self.forMessage.story.timer.getElapsed()
|
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
|
if diff > 5: # time in seconds to force silence in utterance
|
||||||
# useful for eg. 'hello', or 'no'
|
# useful for eg. 'hello', or 'no'
|
||||||
self.forMessage.story.logger.warn(
|
self.forMessage.story.logger.warn(
|
||||||
|
@ -344,9 +344,6 @@ class Condition(object):
|
||||||
return True
|
return True
|
||||||
# TODO: implement 'instant match' -> don't wait for isFinished()
|
# 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)
|
# print(self.vars)
|
||||||
# either there's a match, or nothing to match at all
|
# 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")
|
story.logger.debug("not finished playback yet")
|
||||||
return False
|
return False
|
||||||
# time between finishing playback and ending of speaking:
|
# 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)
|
delays = sorted(self.vars['delays'], key=lambda k: float(k['minReplyDuration']), reverse=True)
|
||||||
for delay in delays:
|
for delay in delays:
|
||||||
if replyDuration > float(delay['minReplyDuration']):
|
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']}")
|
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']):
|
if timeSinceReply > float(delay['waitTime']):
|
||||||
return True
|
return True
|
||||||
break # don't check other delays
|
break # don't check other delays
|
||||||
# wait for delay to match
|
# 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
|
return False
|
||||||
|
|
||||||
# There is a match and no delay say, person finished speaking. Go ahead sir!
|
# There is a match and no delay say, person finished speaking. Go ahead sir!
|
||||||
|
|
Loading…
Reference in a new issue