From 777110ff5c54ddafeef8d73d6cc0165d01ce62df Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Mon, 13 Nov 2023 17:08:56 -0800 Subject: [PATCH] Add response timing context to STT error responses --- neon_speech/service.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/neon_speech/service.py b/neon_speech/service.py index 9dff71a..e6feb36 100644 --- a/neon_speech/service.py +++ b/neon_speech/service.py @@ -335,18 +335,21 @@ def handle_get_stt(self, message: Message): wav_file_path = message.data.get("audio_file") lang = message.data.get("lang") ident = message.context.get("ident") or "neon.get_stt.response" + + message.context.setdefault("timing", dict()) LOG.info(f"Handling STT request: {ident}") if not wav_file_path: + message.context['timing']['response_sent'] = time() self.bus.emit(message.reply( ident, data={"error": f"audio_file not specified!"})) return if not os.path.isfile(wav_file_path): + message.context['timing']['response_sent'] = time() self.bus.emit(message.reply( ident, data={"error": f"{wav_file_path} Not found!"})) try: - message.context.setdefault("timing", dict()) _, parser_data, transcriptions = \ self._get_stt_from_file(wav_file_path, lang) @@ -363,6 +366,7 @@ def handle_get_stt(self, message: Message): "transcripts": transcriptions})) except Exception as e: LOG.error(e) + message.context['timing']['response_sent'] = time() self.bus.emit(message.reply(ident, data={"error": repr(e)})) def handle_audio_input(self, message):