Support for is_muted/toggle_muted on Google assistant

This commit is contained in:
Fabio Manganiello 2020-03-05 18:13:44 +01:00
parent 124d2e356d
commit 27f847eac6
2 changed files with 23 additions and 2 deletions

View file

@ -85,6 +85,7 @@ class AssistantGoogleBackend(AssistantBackend):
self.credentials = None self.credentials = None
self.assistant = None self.assistant = None
self._has_error = False self._has_error = False
self._is_muted = False
self.logger.info('Initialized Google Assistant backend') self.logger.info('Initialized Google Assistant backend')
@ -140,8 +141,8 @@ class AssistantGoogleBackend(AssistantBackend):
else: else:
self.logger.warning('Assistant error') self.logger.warning('Assistant error')
if event.type == EventType.ON_MUTED_CHANGED: if event.type == EventType.ON_MUTED_CHANGED:
muted = event.args.get('is_muted') self._is_muted = event.args.get('is_muted')
event = MicMutedEvent() if muted else MicUnmutedEvent() event = MicMutedEvent() if self._is_muted else MicUnmutedEvent()
self.bus.post(event) self.bus.post(event)
def start_conversation(self): def start_conversation(self):
@ -161,6 +162,9 @@ class AssistantGoogleBackend(AssistantBackend):
self.assistant.set_mic_mute(muted) self.assistant.set_mic_mute(muted)
def is_muted(self) -> bool:
return self._is_muted
def send_text_query(self, query): def send_text_query(self, query):
if not self.assistant: if not self.assistant:
self.logger.warning('Assistant not running') self.logger.warning('Assistant not running')

View file

@ -47,6 +47,23 @@ class AssistantGooglePlugin(AssistantPlugin):
assistant = self._get_assistant() assistant = self._get_assistant()
assistant.set_mic_mute(muted) assistant.set_mic_mute(muted)
@action
def toggle_mic_mute(self):
"""
Toggle the mic mute state.
"""
assistant = self._get_assistant()
is_muted = assistant.is_muted()
self.set_mic_mute(muted=not is_muted)
@action
def is_muted(self) -> bool:
"""
:return: True if the microphone is muted, False otherwise.
"""
assistant = self._get_assistant()
return assistant.is_muted()
@action @action
def send_text_query(self, query: str): def send_text_query(self, query: str):
""" """