diff --git a/platypush/plugins/assistant/google/lib/__init__.py b/platypush/plugins/assistant/google/lib/__init__.py index 6c31bb155..ea5b1c5b3 100644 --- a/platypush/plugins/assistant/google/lib/__init__.py +++ b/platypush/plugins/assistant/google/lib/__init__.py @@ -50,7 +50,7 @@ class SampleAssistant(object): def __init__(self, language_code, device_model_id, device_id, conversation_stream, display, - channel, deadline_sec, device_handler, + channel, deadline_sec, device_handler, play_response=True, on_conversation_start=None, on_conversation_end=None, on_speech_recognized=None, on_volume_changed=None, on_response=None): @@ -59,7 +59,7 @@ class SampleAssistant(object): self.device_id = device_id self.conversation_stream = conversation_stream self.display = display - self.play_response = True + self.play_response = play_response # Opaque blob provided in AssistResponse that, # when provided in a follow-up AssistRequest, @@ -94,6 +94,7 @@ class SampleAssistant(object): return False self.conversation_stream.close() + @staticmethod def is_grpc_error_unavailable(e): is_grpc_error = isinstance(e, grpc.RpcError) if is_grpc_error and (e.code() == grpc.StatusCode.UNAVAILABLE): @@ -115,7 +116,6 @@ class SampleAssistant(object): if self.on_conversation_start: self.on_conversation_start() - self.play_response = True logging.info('Recording audio request.') def iter_log_assist_requests(): diff --git a/platypush/plugins/assistant/google/pushtotalk.py b/platypush/plugins/assistant/google/pushtotalk.py index b814e5002..299595291 100644 --- a/platypush/plugins/assistant/google/pushtotalk.py +++ b/platypush/plugins/assistant/google/pushtotalk.py @@ -55,7 +55,9 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): device_config=os.path.join( os.path.expanduser('~'), '.config', 'googlesamples-assistant', 'device_config.json'), - language='en-US', **kwargs): + language='en-US', + play_response=True, + **kwargs): """ :param credentials_file: Path to the Google OAuth credentials file (default: ~/.config/google-oauthlib-tool/credentials.json). @@ -71,6 +73,10 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): :param language: Assistant language (default: en-US) :type language: str + + :param play_response: If True (default) then the plugin will play the assistant response upon processed + response. Otherwise nothing will be played - but you may want to handle the ``ResponseEvent`` manually. + :type play_response: bool """ super().__init__(**kwargs) @@ -78,6 +84,7 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): self.language = language self.credentials_file = credentials_file self.device_config = device_config + self.play_response = play_response self.assistant = None self.interactions = [] @@ -223,6 +230,7 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): display=None, channel=self.grpc_channel, deadline_sec=self.grpc_deadline, + play_response=self.play_response, device_handler=self.device_handler, on_conversation_start=self.on_conversation_start(), on_conversation_end=self.on_conversation_end(),