From d49c7a12c860ff1d299417122e8fc34934a3b472 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 21 Sep 2019 12:54:31 +0900 Subject: [PATCH] rewrite locale strings to IETF standard and check for model existence --- main/states/recognizing_state.py | 9 ++++++++- main/states/susi_state_machine.py | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/main/states/recognizing_state.py b/main/states/recognizing_state.py index 875c1617..1cf0d886 100644 --- a/main/states/recognizing_state.py +++ b/main/states/recognizing_state.py @@ -41,7 +41,14 @@ def __recognize_audio(self, recognizer, audio): self.components.config['default_stt'] = 'google' return recognizer.recognize_google(audio, language=susi_config["language"]) else: - return recognizer.recognize_sphinx(audio, language=susi_config["language"]) + if susi_config["language"][0:2] == 'it' and 'it-IT' in self.components.pocketsphinx_supported_langs: + sphinxlang = 'it-IT' + elif susi_config["language"][0:2] == 'zh' and 'zh-CN' in self.components.pocketsphinx_supported_langs: + sphinxlang = 'zh-CN' + else: + # fall back to English + sphinxlang = 'en-US' + return recognizer.recognize_sphinx(audio, sphinxlang) elif self.components.config['default_stt'] == 'bing': api_key = self.components.config['bing_speech_api_key'] diff --git a/main/states/susi_state_machine.py b/main/states/susi_state_machine.py index 252d41f8..323d72d3 100644 --- a/main/states/susi_state_machine.py +++ b/main/states/susi_state_machine.py @@ -8,7 +8,8 @@ import requests import json_config - +import os +import speech_recognition from speech_recognition import Recognizer, Microphone from requests.exceptions import ConnectionError @@ -91,6 +92,9 @@ def __init__(self, renderer=None): logger.warning("Susi has the wake button disabled") self.wake_button = None + # determine PocketSphinx supported languages + self.pocketsphinx_supported_langs = os.listdir(os.path.dirname(speech_recognition.__file__) + '/pocketsphinx-data') + def server_checker(self): response_one = None test_params = {