Skip to content

Commit

Permalink
Add timing context handling to get_stt and add test for timing hand…
Browse files Browse the repository at this point in the history
…ling in `audio_input`
  • Loading branch information
NeonDaniel committed Nov 13, 2023
1 parent 229c752 commit edfb492
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion neon_speech/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ def handle_get_stt(self, message: Message):
try:
_, parser_data, transcriptions = \
self._get_stt_from_file(wav_file_path, lang)
received_time = time()
sent_time = message.context.get("timing", {}).get("client_sent",
received_time)
if received_time != sent_time:
message.context['timing']['mq_from_client'] = \
received_time - sent_time
self.bus.emit(message.reply(ident,
data={"parser_data": parser_data,
"transcripts": transcriptions}))
Expand Down Expand Up @@ -380,7 +386,8 @@ def build_context(msg: Message):
sent_time = message.context.get("timing", {}).get("client_sent",
received_time)
if received_time != sent_time:
message.context['timing']['mq_from_client'] = received_time - sent_time
message.context['timing']['mq_from_client'] = \
received_time - sent_time
ident = message.context.get("ident") or "neon.audio_input.response"
LOG.info(f"Handling audio input: {ident}")
if message.data.get("audio_data"):
Expand Down
7 changes: 6 additions & 1 deletion tests/api_method_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def test_audio_input_valid(self):
context = {"client": "tester",
"ident": "11111",
"user": "TestRunner",
"extra_data": "something"}
"extra_data": "something",
"timing": {"client_sent": time()}}
audio_data = encode_file_to_base64_string(os.path.join(AUDIO_FILE_PATH,
"stop.wav"))
stt_resp = self.bus.wait_for_response(Message(
Expand All @@ -199,6 +200,10 @@ def test_audio_input_valid(self):
self.assertIn("stop", message.data["utterances"],
message.data.get("utterances"))
self.assertIsInstance(message.context["timing"], dict)
self.assertIsInstance(stt_resp.context['timing']['mq_from_client'],
float, stt_resp.context)
self.assertIsInstance(stt_resp.context['timing']['transcribed'], float,
stt_resp.context)
self.assertEqual(message.context["destination"], ["skills"])

def test_wake_words_state(self):
Expand Down

0 comments on commit edfb492

Please sign in to comment.