From 659629bd7581eb7b56a8655bdd6cbe1d4879d543 Mon Sep 17 00:00:00 2001 From: Kikkia Date: Wed, 17 Jan 2024 22:31:49 -0800 Subject: [PATCH] add json support to the TTS server api. This allows you to send a json request body with your text and will allow for longer texts that otherwise exceed the maximum http url length --- TTS/server/server.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/TTS/server/server.py b/TTS/server/server.py index 6b2141a9aa..58b0ddca69 100644 --- a/TTS/server/server.py +++ b/TTS/server/server.py @@ -191,10 +191,19 @@ def details(): @app.route("/api/tts", methods=["GET", "POST"]) def tts(): with lock: - text = request.headers.get("text") or request.values.get("text", "") - speaker_idx = request.headers.get("speaker-id") or request.values.get("speaker_id", "") - language_idx = request.headers.get("language-id") or request.values.get("language_id", "") - style_wav = request.headers.get("style-wav") or request.values.get("style_wav", "") + try: + data = request.get_json() + text = data.get("text", "") + speaker_idx = data.get("speaker-id", "") + language_idx = data.get("language-id", "") + style_wav = data.get("style-wav", "") + except: + # Fallback to headers and form data if JSON data is not present + text = request.headers.get("text") or request.values.get("text", "") + speaker_idx = request.headers.get("speaker-id") or request.values.get("speaker_id", "") + language_idx = request.headers.get("language-id") or request.values.get("language_id", "") + style_wav = request.headers.get("style-wav") or request.values.get("style_wav", "") + style_wav = style_wav_uri_to_dict(style_wav) print(f" > Model input: {text}")