From 59029f8398237e3b00b3e43e5c8b34b928376090 Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Sun, 1 Aug 2021 11:48:33 +0200 Subject: [PATCH] added working opentts integration --- jarvis/utils/client_utils.py | 43 +++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/jarvis/utils/client_utils.py b/jarvis/utils/client_utils.py index bbe854c..cd4837d 100644 --- a/jarvis/utils/client_utils.py +++ b/jarvis/utils/client_utils.py @@ -1,15 +1,38 @@ -import os +import requests +from requests.structures import CaseInsensitiveDict from jarvis.utils import config_utils -def speak(sentence, quality=config_utils.get_in_config("LARYNX_QUALITY")): - voice = config_utils.get_in_config("LARYNX_VOICE") - denoiserstrength = config_utils.get_in_config("LARYNX_DENOISER_STRENGTH") +def speak(sentence, client_ip, client_port): + raw_audio_bytes = get_audio_from_sentence(sentence) + play_audio_on_client(raw_audio_bytes, client_ip, client_port) - os.system( - "larynx \"" + sentence + "\" --voice " + voice + " --quality " + quality + - # " --output-dir wav " + - " --interactive " + - "--denoiser-strength " + str(denoiserstrength) + - " --output-naming time") + +def get_audio_from_sentence(sentence): + voice = config_utils.get_in_config("TTS_VOICE") + + headers = {'accept': '*/*'} + + params = ( + ('voice', voice), + ('text', sentence), + ) + + # TODO : add support for external opentts server + response = requests.get('http://localhost:5500/api/tts', headers=headers, params=params) + return response.content + + +def play_audio_on_client(raw_audio_bytes, client_ip, client_port): + url_service = "http://" + client_ip + ":" + client_port + "/play_raw_audio" + + 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, + data=raw_audio_bytes) + + print(response.content)