From aabc779647b43dcd6f8a0d95f0e826f6c2303f7b Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Wed, 27 Mar 2019 13:11:38 -0300 Subject: [PATCH] fixing bug with google stt and fixing device's setting to properly return date format and time format --- api/public/public_api/endpoints/google_stt.py | 17 ++++++++++------- shared/selene/data/device/repository/setting.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/api/public/public_api/endpoints/google_stt.py b/api/public/public_api/endpoints/google_stt.py index 26a5fa97..a2d01e30 100644 --- a/api/public/public_api/endpoints/google_stt.py +++ b/api/public/public_api/endpoints/google_stt.py @@ -24,13 +24,16 @@ class GoogleSTTEndpoint(PublicEndpoint): response = self.recognizer.recognize_google(data, key=self.google_stt_key, language=lang, show_all=True) if isinstance(response, dict): alternative = response.get("alternative") - # Sorting by confidence: - alternative = sorted(alternative, key=lambda alt: alt['confidence'], reverse=True) - alternative = [alt['transcript'] for alt in alternative] - # Return n transcripts with the higher confidence. That is useful for the case when send a ambiguous - # voice file and the correct utterance is not the utterance with highest confidence and the API client - # is interested in test the utterances found. - result = alternative if len(alternative) <= limit else alternative[:limit] + if 'confidence' in alternative: + # Sorting by confidence: + alternative = sorted(alternative, key=lambda alt: alt['confidence'], reverse=True) + alternative = [alt['transcript'] for alt in alternative] + # Return n transcripts with the higher confidence. That is useful for the case when send a ambiguous + # voice file and the correct utterance is not the utterance with highest confidence and the API + # client is interested in test the utterances found. + result = alternative if len(alternative) <= limit else alternative[:limit] + else: + result = [alternative[0]['transcript']] else: result = [] return result diff --git a/shared/selene/data/device/repository/setting.py b/shared/selene/data/device/repository/setting.py index 1a9cb945..de2dcaee 100644 --- a/shared/selene/data/device/repository/setting.py +++ b/shared/selene/data/device/repository/setting.py @@ -29,6 +29,20 @@ class SettingRepository(object): else: return 'google', '' + def _format_date_v1(self, date: str): + if date == 'DD/MM/YYYY': + result = 'DMY' + else: + result = 'MDY' + return result + + def _format_time_v1(self, time: str): + if time == '24 Hour': + result = 'full' + else: + result = 'half' + return result + def get_device_settings(self, device_id): """Return the device settings aggregating the tables account preference, text to speech, wake word and wake word settings @@ -42,6 +56,8 @@ class SettingRepository(object): tts_setting = self.convert_text_to_speech_setting(tts_setting['setting_name'], tts_setting['engine']) tts_setting = [{'@type': tts_setting[0], 'voice': tts_setting[1]}] response['tts_settings'] = tts_setting + response['date_format'] = self._format_date_v1(response['date_format']) + response['time_format'] = self._format_time_v1(response['time_format']) return response def add_account_preferences(self, preferences: dict):