[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
google-assistant-sdk/pushtotalk: only start recording when we get aud…
Browse files Browse the repository at this point in the history
…io data

Change-Id: Icfd2e3a01ddbb35e17e54b53f26091580bf31f0f
  • Loading branch information
proppy committed Mar 27, 2018
1 parent 2dfc868 commit e7521ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions google-assistant-sdk/googlesamples/assistant/grpc/audio_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,12 @@ def __init__(self, source, sink, iter_size, sample_width):
self._volume_percentage = 50
self._stop_recording = threading.Event()
self._source_lock = threading.RLock()
self._recording = False
self._playing = False

def start_recording(self):
"""Start recording from the audio source."""
self._recording = True
self._stop_recording.clear()
self._source.start()

Expand All @@ -280,15 +283,26 @@ def stop_recording(self):
self._stop_recording.set()
with self._source_lock:
self._source.stop()
self._recording = False

def start_playback(self):
"""Start playback to the audio sink."""
self._playing = True
self._sink.start()

def stop_playback(self):
"""Stop playback from the audio sink."""
self._sink.flush()
self._sink.stop()
self._playing = False

@property
def recording(self):
return self._recording

@property
def playing(self):
return self._playing

@property
def volume_percentage(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ def iter_log_assist_requests():
logging.info('Transcript of user request: "%s".',
' '.join(r.transcript
for r in resp.speech_results))
self.conversation_stream.start_playback()
logging.info('Playing assistant response.')
if len(resp.audio_out.audio_data) > 0:
if not self.conversation_stream.playing:
self.conversation_stream.start_playback()
logging.info('Playing assistant response.')
self.conversation_stream.write(resp.audio_out.audio_data)
if resp.dialog_state_out.conversation_state:
conversation_state = resp.dialog_state_out.conversation_state
Expand Down

0 comments on commit e7521ed

Please sign in to comment.