Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Oct 10, 2023
1 parent aff0af7 commit 973f05e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions neon_minerva/integration/user_utterance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
from ovos_utils.log import LOG
from ovos_bus_client.client import MessageBusClient
from ovos_bus_client.message import Message
from ovos_plugin_manager.tts import OVOSTTSFactory
from ovos_plugin_manager.tts import OVOSTTSFactory, TTS


class UtteranceTests:
def __init__(self, prompts: List[str], lang: str = "en-us",
bus_config: dict = None, user_config: dict = None,
audio: bool = False):
audio: bool = False, tts: TTS = None):
if not user_config:
from neon_utils.configuration_utils import get_neon_user_config
user_config = get_neon_user_config().content
Expand All @@ -49,7 +49,7 @@ def __init__(self, prompts: List[str], lang: str = "en-us",
self.core_bus.run_in_thread()
self.lang = lang
self.test_audio = audio
self._tts = OVOSTTSFactory.create() if audio else None
self._tts = tts or OVOSTTSFactory.create() if audio else None
# TODO: Handle prompt metadata for longer timeouts
self._prompts = prompts
self._stt_timeout = 60
Expand All @@ -66,6 +66,9 @@ def __init__(self, prompts: List[str], lang: str = "en-us",
self.register_bus_events()

def run_test(self) -> dict:
"""
Run tests and return dict timing results
"""
self._results.clear()
for prompt in self._prompts:
self.handle_prompt(prompt)
Expand Down Expand Up @@ -95,6 +98,9 @@ def run_test(self) -> dict:
return formatted_results

def register_bus_events(self):
"""
Register listeners to track audio and skill module states
"""
self.core_bus.on("recognizer_loop:audio_output_start",
self._audio_started)
self.core_bus.on("recognizer_loop:audio_output_end",
Expand Down Expand Up @@ -162,6 +168,11 @@ def send_prompt(self, prompt: str):
"lang": self.lang}, context))

def handle_prompt(self, prompt: str):
"""
Send a prompt (text or audio) and collect timing results.
@param prompt: string prompt to send for intent (and optionally STT)
processing
"""
with self._prompt_lock:
# Ensure event state matches expectation
if not self._audio_output_done.is_set():
Expand Down

0 comments on commit 973f05e

Please sign in to comment.