Support for is_muted/toggle_muted on Google assistant
This commit is contained in:
parent
124d2e356d
commit
27f847eac6
2 changed files with 23 additions and 2 deletions
|
@ -85,6 +85,7 @@ class AssistantGoogleBackend(AssistantBackend):
|
|||
self.credentials = None
|
||||
self.assistant = None
|
||||
self._has_error = False
|
||||
self._is_muted = False
|
||||
|
||||
self.logger.info('Initialized Google Assistant backend')
|
||||
|
||||
|
@ -140,8 +141,8 @@ class AssistantGoogleBackend(AssistantBackend):
|
|||
else:
|
||||
self.logger.warning('Assistant error')
|
||||
if event.type == EventType.ON_MUTED_CHANGED:
|
||||
muted = event.args.get('is_muted')
|
||||
event = MicMutedEvent() if muted else MicUnmutedEvent()
|
||||
self._is_muted = event.args.get('is_muted')
|
||||
event = MicMutedEvent() if self._is_muted else MicUnmutedEvent()
|
||||
self.bus.post(event)
|
||||
|
||||
def start_conversation(self):
|
||||
|
@ -161,6 +162,9 @@ class AssistantGoogleBackend(AssistantBackend):
|
|||
|
||||
self.assistant.set_mic_mute(muted)
|
||||
|
||||
def is_muted(self) -> bool:
|
||||
return self._is_muted
|
||||
|
||||
def send_text_query(self, query):
|
||||
if not self.assistant:
|
||||
self.logger.warning('Assistant not running')
|
||||
|
|
|
@ -47,6 +47,23 @@ class AssistantGooglePlugin(AssistantPlugin):
|
|||
assistant = self._get_assistant()
|
||||
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
|
||||
def send_text_query(self, query: str):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue