fixing bug with google stt and fixing device's setting to properly return date format and time format

pull/86/head
Matheus Lima 2019-03-27 13:11:38 -03:00
parent dac786238d
commit aabc779647
2 changed files with 26 additions and 7 deletions

View File

@ -24,13 +24,16 @@ class GoogleSTTEndpoint(PublicEndpoint):
response = self.recognizer.recognize_google(data, key=self.google_stt_key, language=lang, show_all=True) response = self.recognizer.recognize_google(data, key=self.google_stt_key, language=lang, show_all=True)
if isinstance(response, dict): if isinstance(response, dict):
alternative = response.get("alternative") alternative = response.get("alternative")
# Sorting by confidence: if 'confidence' in alternative:
alternative = sorted(alternative, key=lambda alt: alt['confidence'], reverse=True) # Sorting by confidence:
alternative = [alt['transcript'] for alt in alternative] alternative = sorted(alternative, key=lambda alt: alt['confidence'], reverse=True)
# Return n transcripts with the higher confidence. That is useful for the case when send a ambiguous alternative = [alt['transcript'] for alt in alternative]
# voice file and the correct utterance is not the utterance with highest confidence and the API client # Return n transcripts with the higher confidence. That is useful for the case when send a ambiguous
# is interested in test the utterances found. # voice file and the correct utterance is not the utterance with highest confidence and the API
result = alternative if len(alternative) <= limit else alternative[:limit] # client is interested in test the utterances found.
result = alternative if len(alternative) <= limit else alternative[:limit]
else:
result = [alternative[0]['transcript']]
else: else:
result = [] result = []
return result return result

View File

@ -29,6 +29,20 @@ class SettingRepository(object):
else: else:
return 'google', '' 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): def get_device_settings(self, device_id):
"""Return the device settings aggregating the tables account preference, text to speech, wake word and """Return the device settings aggregating the tables account preference, text to speech, wake word and
wake word settings 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 = self.convert_text_to_speech_setting(tts_setting['setting_name'], tts_setting['engine'])
tts_setting = [{'@type': tts_setting[0], 'voice': tts_setting[1]}] tts_setting = [{'@type': tts_setting[0], 'voice': tts_setting[1]}]
response['tts_settings'] = tts_setting 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 return response
def add_account_preferences(self, preferences: dict): def add_account_preferences(self, preferences: dict):