From ef8fd044fdcd4f89d953efccc0e4b88142b7695d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 24 Nov 2019 23:57:32 +0100 Subject: [PATCH] #80: Extended Alexa/Echo plugin --- platypush/plugins/assistant/echo/__init__.py | 15 +++++++++++---- platypush/plugins/assistant/echo/requirements.txt | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 platypush/plugins/assistant/echo/requirements.txt diff --git a/platypush/plugins/assistant/echo/__init__.py b/platypush/plugins/assistant/echo/__init__.py index ea6163860..ce5498a49 100644 --- a/platypush/plugins/assistant/echo/__init__.py +++ b/platypush/plugins/assistant/echo/__init__.py @@ -14,8 +14,7 @@ from platypush.plugins import action from platypush.plugins.assistant import AssistantPlugin from platypush.message.event.assistant import ConversationStartEvent, \ - ConversationEndEvent, SpeechRecognizedEvent, VolumeChangedEvent, \ - ResponseEvent + ConversationEndEvent, SpeechRecognizedEvent, ResponseEvent class AssistantEchoPlugin(AssistantPlugin): @@ -44,14 +43,14 @@ class AssistantEchoPlugin(AssistantPlugin): * **avs** (``pip install avs``) """ - def __init__(self, avs_config_file=DEFAULT_CONFIG_FILE, **kwargs): + def __init__(self, avs_config_file=DEFAULT_CONFIG_FILE, language='en-US', **kwargs): """ :param avs_config_file: AVS credentials file - default: ~/.avs.json. If the file doesn't exist then an instance of the AVS authentication service will be spawned. You can login through an Amazon account either in the spawned browser window, if available, or by opening http://your-ip:3000 in the browser on another machine. """ - super().__init__(**kwargs) + super().__init__(language=language, **kwargs) if not avs_config_file or not os.path.isfile(avs_config_file): auth(None, avs_config_file) @@ -65,6 +64,7 @@ class AssistantEchoPlugin(AssistantPlugin): self.alexa.state_listener.on_ready = self._on_ready() self.alexa.state_listener.on_listening = self._on_listening() self.alexa.state_listener.on_speaking = self._on_speaking() + self.alexa.state_listener.on_thinking = self._on_thinking() self.alexa.state_listener.on_finished = self._on_finished() self.alexa.state_listener.on_disconnected = self._on_disconnected() @@ -100,6 +100,13 @@ class AssistantEchoPlugin(AssistantPlugin): self._ready = False return _callback + @staticmethod + def _on_thinking(): + def _callback(): + # AVS doesn't provide a way to access the detected text + get_bus().post(SpeechRecognizedEvent(phrase='')) + return _callback + @action def start_conversation(self): """ diff --git a/platypush/plugins/assistant/echo/requirements.txt b/platypush/plugins/assistant/echo/requirements.txt new file mode 100644 index 000000000..79acd185f --- /dev/null +++ b/platypush/plugins/assistant/echo/requirements.txt @@ -0,0 +1 @@ +avs \ No newline at end of file