From c23390cb790fbcbfdb0eb5b46cb32fd03f2d9953 Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Sun, 1 Aug 2021 23:15:03 +0200 Subject: [PATCH] various little improvements --- jarvis/skills/__init__.py | 4 +++- jarvis/utils/client_utils.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/jarvis/skills/__init__.py b/jarvis/skills/__init__.py index 8214180..2b72479 100644 --- a/jarvis/skills/__init__.py +++ b/jarvis/skills/__init__.py @@ -37,9 +37,11 @@ class Skill: for key, val in data.items(): if "{{" + key + "}}" in random_line: + # TODO: replace when found a better TTS engine for french # as the french tts don't support float in sentence, convert it to an integer if is_float(val): - val = str(int(float(val))) + # val = str(int(float(val))) # convert a float to integer + val = str(val).split(".")[0] + " virgule " + str(val).split(".")[1] random_line = random_line.replace("{{" + key + "}}", val) diff --git a/jarvis/utils/client_utils.py b/jarvis/utils/client_utils.py index cd4837d..6dcf98f 100644 --- a/jarvis/utils/client_utils.py +++ b/jarvis/utils/client_utils.py @@ -6,6 +6,9 @@ from jarvis.utils import config_utils def speak(sentence, client_ip, client_port): raw_audio_bytes = get_audio_from_sentence(sentence) + if raw_audio_bytes is None: + return "Error, audio not valid!" + play_audio_on_client(raw_audio_bytes, client_ip, client_port) @@ -20,8 +23,12 @@ def get_audio_from_sentence(sentence): ) # TODO : add support for external opentts server - response = requests.get('http://localhost:5500/api/tts', headers=headers, params=params) - return response.content + try: + response = requests.get('http://localhost:5500/api/tts', headers=headers, params=params) + return response.content + except requests.exceptions.ConnectionError: + print("Error connecting to Open TTS server") + return None def play_audio_on_client(raw_audio_bytes, client_ip, client_port): @@ -29,7 +36,6 @@ def play_audio_on_client(raw_audio_bytes, client_ip, client_port): headers = CaseInsensitiveDict() headers["Content-Type"] = "text/xml; charset=utf8" - # headers["Authorization"] = config_utils.get_in_config("API_KEY") response = requests.post(url_service, headers=headers,