Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug causing get_stt and get_tts request failures #53

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions neon_messagebus_mq_connector/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,21 @@ def handle_neon_message(self, message: Message):
message.data['msg'] = 'Failed to get response from Neon'
message.context.setdefault('klat_data', {})
message.context.setdefault('mq', {})
if message.msg_type == 'neon.get_tts.response':
body = self.format_response(response_type=NeonResponseTypes.TTS,
message=message)
message.context['mq'].setdefault('routing_key', 'neon_tts_response')
elif message.msg_type == 'neon.get_stt.response':
body = self.format_response(response_type=NeonResponseTypes.STT,
message=message)
message.context['mq'].setdefault('routing_key', 'neon_stt_response')
# TODO: Can Klat parse a generic Neon response instead of extra parsing
# here?
if message.context['klat_data'].get("sid"):
LOG.debug(f"Formatting klat response for: "
f"{message.context['klat_data']['sid']}")
response_type = NeonResponseTypes.TTS if \
message.msg_type == "neon.get_tts.response" else \
NeonResponseTypes.STT if \
message.msg_type == "neon.get_stt.response" else None
body = self.format_response(response_type, message)
else:
body = {'msg_type': message.msg_type,
'data': message.data, 'context': message.context}
_stopwatch.stop()
LOG.debug(f'Processed neon response: {body["msg_type"]} in '
LOG.debug(f'Processed neon response: {body.get("msg_type")} in '
f'{_stopwatch.time}s')
if not body:
LOG.warning('Something went wrong while formatting - '
Expand Down Expand Up @@ -397,8 +399,8 @@ def format_response(self, response_type: NeonResponseTypes,
if int(time.time()) - message.context.get('created_on', 0) > timeout:
LOG.warning(f'Message = {message} received timeout on '
f'{response_type} (>{timeout} seconds)')
response_data = {}
elif response_type == NeonResponseTypes.TTS:
return {}
if response_type == NeonResponseTypes.TTS:
lang = list(message.data)[0]
gender = message.data[lang].get('genders', ['female'])[0]
audio_data_b64 = message.data[lang]['audio'][gender]
Expand Down
Loading