Always pause/resume speech detection on backend level

This commit is contained in:
Fabio Manganiello 2020-01-19 16:32:41 +01:00
parent 6c797b0ad9
commit f38121d176
4 changed files with 17 additions and 58 deletions

View File

@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from platypush.plugins import Plugin
from platypush.context import get_backend
from platypush.plugins import Plugin, action
class AssistantPlugin(ABC, Plugin):
@ -22,26 +23,32 @@ class AssistantPlugin(ABC, Plugin):
"""
raise NotImplementedError
@abstractmethod
def pause_detection(self, *args, **kwargs):
def _get_assistant(self):
return get_backend('assistant.snowboy')
@action
def pause_detection(self):
"""
Put the assistant on pause. No new conversation events will be triggered.
"""
raise NotImplementedError
assistant = self._get_assistant()
assistant.pause_detection()
@abstractmethod
def resume_detection(self, *args, **kwargs):
@action
def resume_detection(self):
"""
Resume the assistant hotword detection from a paused state.
"""
raise NotImplementedError
assistant = self._get_assistant()
assistant.resume_detection()
@abstractmethod
@action
def is_detecting(self) -> bool:
"""
:return: True if the asistant is detecting, False otherwise.
"""
raise NotImplementedError
assistant = self._get_assistant()
return assistant.is_detecting()
# vim:sw=4:ts=4:et:

View File

@ -3,7 +3,6 @@
"""
import os
import threading
from platypush.context import get_bus
from platypush.plugins import action
@ -71,7 +70,6 @@ class AssistantEchoPlugin(AssistantPlugin):
self.audio = Audio(device_name=audio_device)
self.alexa = Alexa(avs_config_file, audio_player=audio_player)
self._ready = False
self._detection_paused = threading.Event()
self.alexa.state_listener.on_ready = self._on_ready()
self.alexa.state_listener.on_listening = self._on_listening()
@ -128,17 +126,5 @@ class AssistantEchoPlugin(AssistantPlugin):
self.audio.stop()
self._on_finished()()
@action
def pause_detection(self):
self._detection_paused.set()
@action
def resume_detection(self):
self._detection_paused.clear()
@action
def is_detecting(self) -> bool:
return not self._detection_paused.is_set()
# vim:sw=4:ts=4:et:

View File

@ -17,8 +17,7 @@ class AssistantGooglePlugin(AssistantPlugin):
def __init__(self, **kwargs):
super().__init__(**kwargs)
@staticmethod
def _get_assistant():
def _get_assistant(self):
return get_backend('assistant.google')
@action
@ -37,20 +36,5 @@ class AssistantGooglePlugin(AssistantPlugin):
assistant = self._get_assistant()
assistant.stop_conversation()
@action
def pause_detection(self):
assistant = self._get_assistant()
assistant.pause_detection()
@action
def resume_detection(self):
assistant = self._get_assistant()
assistant.resume_detection()
@action
def is_detecting(self) -> bool:
assistant = self._get_assistant()
return assistant.is_detecting()
# vim:sw=4:ts=4:et:

View File

@ -4,7 +4,6 @@
import json
import os
import threading
from platypush.context import get_bus
from platypush.message.event.assistant import ConversationStartEvent, \
@ -86,7 +85,6 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
self.play_response = play_response
self.assistant = None
self.interactions = []
self._detection_paused = threading.Event()
with open(self.device_config) as f:
device = json.load(f)
@ -221,10 +219,6 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
from platypush.plugins.assistant.google.lib import SampleAssistant
if not self.is_detecting():
self.logger.info('Conversation start event received but detection is currently paused')
return
if not language:
language = self.language
@ -279,17 +273,5 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
device_model_id=self.device_model_id,
on=on))
@action
def pause_detection(self):
self._detection_paused.set()
@action
def resume_detection(self):
self._detection_paused.clear()
@action
def is_detecting(self) -> bool:
return not self._detection_paused.is_set()
# vim:sw=4:ts=4:et: