forked from platypush/platypush
- Stop assistant playback only if there was a user request. This
prevents a PortAudio write on input-only stream error in the Assistant SDK, see https://github.com/googlesamples/assistant-sdk-python/issues/185 - Make sure that user_request is always defined before returning it - Use assistant.google.pushtotalk as a fallback if assistant.google is not configured/available
This commit is contained in:
parent
d5f73023ea
commit
a14d6fe652
4 changed files with 47 additions and 3 deletions
|
@ -159,6 +159,7 @@ class AssistantGooglePushtotalkBackend(Backend):
|
|||
|
||||
logging.info('Assistant conversation triggered')
|
||||
continue_conversation = True
|
||||
user_request = None
|
||||
|
||||
while continue_conversation:
|
||||
(user_request, continue_conversation) = self.assistant.assist()
|
||||
|
@ -243,6 +244,8 @@ class SampleAssistant(object):
|
|||
yield c
|
||||
self.conversation_stream.start_playback()
|
||||
|
||||
user_request = None
|
||||
|
||||
# This generator yields AssistResponse proto messages
|
||||
# received from the gRPC Google Assistant API.
|
||||
for resp in self.assistant.Assist(iter_assist_requests(),
|
||||
|
@ -285,7 +288,9 @@ class SampleAssistant(object):
|
|||
concurrent.futures.wait(device_actions_futures)
|
||||
|
||||
logging.info('Finished playing assistant response.')
|
||||
self.conversation_stream.stop_playback()
|
||||
|
||||
if user_request:
|
||||
self.conversation_stream.stop_playback()
|
||||
return (user_request, continue_conversation)
|
||||
|
||||
def gen_assist_requests(self):
|
||||
|
|
|
@ -12,8 +12,11 @@ class AssistantEvent(Event):
|
|||
try:
|
||||
self._assistant = get_backend('assistant.google')
|
||||
except KeyError as e:
|
||||
logging.warning('google.assistant backend not configured/initialized')
|
||||
self._assistant = None
|
||||
try:
|
||||
self._assistant = get_backend('assistant.google.pushtotalk')
|
||||
except KeyError as e:
|
||||
logging.warning('google.assistant backend not configured/initialized')
|
||||
self._assistant = None
|
||||
|
||||
|
||||
class ConversationStartEvent(AssistantEvent):
|
||||
|
|
18
platypush/plugins/assistant/google/__init__.py
Normal file
18
platypush/plugins/assistant/google/__init__.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from platypush.context import get_backend
|
||||
from platypush.message.response import Response
|
||||
|
||||
from platypush.plugins import Plugin
|
||||
|
||||
class AssistantGooglePlugin(Plugin):
|
||||
def start_conversation(self):
|
||||
assistant = get_backend('assistant.google')
|
||||
assistant.start_conversation()
|
||||
return Response(output='', errors=[])
|
||||
|
||||
def stop_conversation(self):
|
||||
assistant = get_backend('assistant.google')
|
||||
assistant.stop_conversation()
|
||||
return Response(output='', errors=[])
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
18
platypush/plugins/assistant/google/pushtotalk.py
Normal file
18
platypush/plugins/assistant/google/pushtotalk.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from platypush.context import get_backend
|
||||
from platypush.message.response import Response
|
||||
|
||||
from platypush.plugins import Plugin
|
||||
|
||||
class AssistantGooglePushtotalkPlugin(Plugin):
|
||||
def start_conversation(self):
|
||||
assistant = get_backend('assistant.google.pushtotalk')
|
||||
assistant.start_conversation()
|
||||
return Response(output='', errors=[])
|
||||
|
||||
def stop_conversation(self):
|
||||
assistant = get_backend('assistant.google.pushtotalk')
|
||||
assistant.stop_conversation()
|
||||
return Response(output='', errors=[])
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
Loading…
Reference in a new issue