From f356fcd84436575d121bf2ce61155771f83400f1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 2 Jun 2024 00:50:25 +0200 Subject: [PATCH] Added `tts.stop` method. --- platypush/plugins/assistant/__init__.py | 18 ++++++++---------- platypush/plugins/assistant/google/__init__.py | 3 +-- platypush/plugins/tts/__init__.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/platypush/plugins/assistant/__init__.py b/platypush/plugins/assistant/__init__.py index ba9d45de8e..79f12557f3 100644 --- a/platypush/plugins/assistant/__init__.py +++ b/platypush/plugins/assistant/__init__.py @@ -1,4 +1,4 @@ -from abc import ABC, abstractmethod +from abc import ABC from dataclasses import asdict, dataclass from enum import Enum import os @@ -111,19 +111,17 @@ class AssistantPlugin(Plugin, AssistantEntityManager, ABC): alert_state=self._cur_alert_type.value if self._cur_alert_type else None, ) - @abstractmethod - def start_conversation(self, *_, **__): - """ - Programmatically starts a conversation. - """ - raise NotImplementedError - - @abstractmethod + @action def stop_conversation(self, *_, **__): """ Programmatically stops a conversation. """ - raise NotImplementedError + self._stop_conversation() + + def _stop_conversation(self, *_, **__): + tts = self._get_tts_plugin() + if tts: + tts.stop() @action def pause_detection(self, *_, **__): diff --git a/platypush/plugins/assistant/google/__init__.py b/platypush/plugins/assistant/google/__init__.py index ca113707cd..4dd13fa041 100644 --- a/platypush/plugins/assistant/google/__init__.py +++ b/platypush/plugins/assistant/google/__init__.py @@ -181,8 +181,7 @@ class AssistantGooglePlugin(AssistantPlugin, RunnablePlugin): if self.assistant: self.assistant.start_conversation() - @action - def stop_conversation(self, *_, **__): + def _stop_conversation(self, *_, **__): """ Programmatically stop a running conversation with the assistant """ diff --git a/platypush/plugins/tts/__init__.py b/platypush/plugins/tts/__init__.py index 6bd2e8bc10..0fa2a13af8 100644 --- a/platypush/plugins/tts/__init__.py +++ b/platypush/plugins/tts/__init__.py @@ -55,5 +55,18 @@ class TtsPlugin(Plugin): self._playback(url, **player_args) + @action + def stop(self): + """ + Stop the playback. + """ + try: + audio = get_plugin('sound') + except Exception: + return + + if audio: + audio.stop_playback() + # vim:sw=4:ts=4:et: