Add volume to playback, and better Google ASR resource management
This commit is contained in:
parent
cc03473361
commit
4498e31d0c
2 changed files with 24 additions and 10 deletions
|
@ -58,13 +58,19 @@ class GoogleVoiceClient(object):
|
|||
self.isRunning.set()
|
||||
|
||||
def generator(self):
|
||||
print('start generator')
|
||||
while not self.toBeShutdown and self.isRunning.is_set():
|
||||
try:
|
||||
# set a timeout, as not to wait infinitely for the buffer when
|
||||
# we actually want to restart
|
||||
yield self.buffer.get(timeout=.2)
|
||||
yield self.buffer.get(timeout=.3)
|
||||
except queue.Empty as e:
|
||||
self.logger.debug('empty mic buffer - restart?')
|
||||
print(self.isRunning.isSet())
|
||||
print('stop generator')
|
||||
self.restart = False # don't trigger double restart
|
||||
|
||||
# raise RequireRestart("Restart required (generator)")
|
||||
|
||||
def setLanguage(self, language_code):
|
||||
if self.language_code == language_code:
|
||||
|
@ -77,12 +83,6 @@ class GoogleVoiceClient(object):
|
|||
def run(self):
|
||||
self.isRunning.set()
|
||||
|
||||
while not self.toBeShutdown:
|
||||
try:
|
||||
self.logger.info("wait for Google Voice")
|
||||
self.isRunning.wait()
|
||||
self.logger.info("Starting Google Voice")
|
||||
|
||||
self.speech_client = speech.SpeechClient()
|
||||
config = types.RecognitionConfig(
|
||||
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
|
||||
|
@ -92,6 +92,13 @@ class GoogleVoiceClient(object):
|
|||
config=config,
|
||||
interim_results=True)
|
||||
|
||||
while not self.toBeShutdown:
|
||||
try:
|
||||
self.logger.info("wait for Google Voice")
|
||||
self.isRunning.wait()
|
||||
self.logger.info("Starting Google Voice")
|
||||
|
||||
|
||||
audio_generator = self.generator()
|
||||
requests = (types.StreamingRecognizeRequest(audio_content=content)
|
||||
for content in audio_generator)
|
||||
|
@ -137,6 +144,8 @@ class GoogleVoiceClient(object):
|
|||
self.logger.info(f"Text: {transcript}")
|
||||
self.lastNonFinalTranscript = None
|
||||
|
||||
if result.is_final:
|
||||
print("native final")
|
||||
msg = {
|
||||
"event": "speech",
|
||||
"is_final": result.is_final,
|
||||
|
@ -153,6 +162,7 @@ class GoogleVoiceClient(object):
|
|||
self.logger.warn("Stopping voice loop")
|
||||
break
|
||||
except RequireRestart as e:
|
||||
self.restart = False
|
||||
self.logger.warn("Restart Google Voice. Language: {}".format(self.language_code))
|
||||
except Exception as e:
|
||||
self.logger.critical(f"Crashed Google Voice: {e}")
|
||||
|
|
|
@ -66,6 +66,9 @@ class Message(object):
|
|||
msg.setStory(story)
|
||||
if 'params' in data:
|
||||
msg.params = data['params']
|
||||
if not 'vol' in msg.params:
|
||||
# prevent clipping on some Lyrebird tracks
|
||||
msg.params['vol'] = .8
|
||||
return msg
|
||||
|
||||
def parseForVariables(self):
|
||||
|
@ -191,7 +194,8 @@ class Reply(object):
|
|||
|
||||
now = self.forMessage.story.timer.getElapsed()
|
||||
diff = now - u.lastUpdate
|
||||
if diff > 2: # 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'
|
||||
self.forMessage.story.logger.warn(
|
||||
f"Set finish time for utterance after {diff}s {u.text}"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue