Skip to content

Commit

Permalink
Add response timing context to STT error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Nov 14, 2023
1 parent ce0ed06 commit 777110f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion neon_speech/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit 777110f

Please sign in to comment.