Skip to content

Commit

Permalink
Update get_tts stopwatch to report measured metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Nov 17, 2023
1 parent 3f1832a commit b772690
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions neon_audio/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def on_started():


class NeonPlaybackService(PlaybackService):
_stopwatch = Stopwatch("get_tts")

def __init__(self, ready_hook=on_ready, error_hook=on_error,
stopping_hook=on_stopping, alive_hook=on_alive,
started_hook=on_started, watchdog=lambda: None,
Expand Down Expand Up @@ -162,15 +160,16 @@ def handle_get_tts(self, message):
f"core defaults will be used.")
message.context.setdefault('timing', dict())
if text:
stopwatch = Stopwatch("get_tts", allow_reporting=True, bus=self.bus)
if not isinstance(text, str):
message.context['timing']['response_sent'] = time()
self.bus.emit(message.reply(
ident, data={"error": f"text is not a str: {text}"}))
return
try:
with self._stopwatch:
with stopwatch:
responses = self.tts.get_multiple_tts(message)
message.context['timing']['get_tts'] = self._stopwatch.time
message.context['timing']['get_tts'] = stopwatch.time
LOG.debug(f"Emitting response: {responses}")
message.context['timing']['response_sent'] = time()
self.bus.emit(message.reply(ident, data=responses))
Expand Down

0 comments on commit b772690

Please sign in to comment.