Skip to content

Commit

Permalink
Update language support to use combined API
Browse files Browse the repository at this point in the history
Ensure default lang populates settings fields
  • Loading branch information
NeonDaniel committed Nov 29, 2023
1 parent 3213820 commit 743a341
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
27 changes: 9 additions & 18 deletions neon_iris/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ def __init__(self, mq_config: dict = None, config_dir: str = None):

# Collect supported languages
if config.get("enable_lang_api"):
message = self._build_message("ovos.languages.stt", {})
self._send_message(message)
message = self._build_message("ovos.languages.tts", {})
message = self._build_message("neon.languages.get", {})
self._send_message(message)

if self._language_init.wait(30):
LOG.info(f"Got language support: {self._languages}")
LOG.debug(f"Got language support: {self._languages}")

if not self._languages:
lang_config = config.get('languages') or []
Expand Down Expand Up @@ -179,9 +177,7 @@ def handle_neon_response(self, channel, method, _, body):
self._handle_clear_data(message)
elif message.msg_type == "klat.error":
self.handle_error_response(message)
elif message.msg_type == "ovos.languages.stt.response":
self._handle_supported_languages(message)
elif message.msg_type == "ovos.languages.tts.response":
elif message.msg_type == "neon.languages.get.response":
self._handle_supported_languages(message)
elif message.msg_type.endswith(".response"):
self.handle_api_response(message)
Expand Down Expand Up @@ -268,17 +264,12 @@ def _clear_audio_cache():
# ALL_MEDIA, ALL_UNITS, ALL_LANGUAGE

def _handle_supported_languages(self, message: Message):
if message.msg_type == "ovos.languages.stt.response":
LOG.debug("STT langauge response")
self._languages["stt"] = message.data.get("langs")
elif message.msg_type == "ovos.languages.tts.response":
LOG.debug("TTS language response")
self._languages["tts"] = message.data.get("langs")
else:
raise RuntimeError(f"Unexpected message type: {message.msg_type}")
if all((x in self._languages for x in ("stt", "tts"))):
LOG.info(f"Language support determined: {self._languages}")
self._language_init.set()
self._languages = message.data
if not all((x in self._languages for x in ("stt", "tts"))):
LOG.warning(f"Language support incomplete response: {self._languages}")
self._languages['stt'].sort()
self._languages['tts'].sort()
self._language_init.set()

def send_utterance(self, utterance: str, lang: str = "en-us",
username: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion neon_iris/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def run(self):
# Define settings UI
with gradio.Row():
with gradio.Column():
lang = self.get_lang(client_session.value)
lang = self.get_lang(client_session.value).split('-')[0]
stt_lang = gradio.Radio(label="Input Language",
choices=self._languages.get("stt")
or self.supported_languages,
Expand Down

0 comments on commit 743a341

Please sign in to comment.