From edfb492477b52fa4e7efda80d49c824ca2da22cb Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Mon, 13 Nov 2023 13:22:35 -0800 Subject: [PATCH] Add timing context handling to `get_stt` and add test for timing handling in `audio_input` --- neon_speech/service.py | 9 ++++++++- tests/api_method_tests.py | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/neon_speech/service.py b/neon_speech/service.py index 4d084d2..beadbec 100644 --- a/neon_speech/service.py +++ b/neon_speech/service.py @@ -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})) @@ -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"): diff --git a/tests/api_method_tests.py b/tests/api_method_tests.py index 19a9007..3d4dd0e 100644 --- a/tests/api_method_tests.py +++ b/tests/api_method_tests.py @@ -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( @@ -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):