diff --git a/mimic3_http/app.py b/mimic3_http/app.py index d8bc6d4..ee4798a 100644 --- a/mimic3_http/app.py +++ b/mimic3_http/app.py @@ -153,7 +153,11 @@ def get_app(args: argparse.Namespace, request_queue: Queue, temp_dir: str): @app.route("/") async def app_index(): """Main page.""" - return await render_template("index.html", show_openapi=show_openapi) + return await render_template( + "index.html", + show_openapi=show_openapi, + max_text_length=args.max_text_length, + ) @app.route("/api/tts", methods=["GET", "POST"]) async def app_tts() -> Response: @@ -206,6 +210,9 @@ def get_app(args: argparse.Namespace, request_queue: Queue, temp_dir: str): assert text, "No text provided" + if args.max_text_length is not None: + text = text[: args.max_text_length] + # Cache settings no_cache_str = request.args.get("noCache", "") no_cache = _to_bool(no_cache_str) @@ -237,6 +244,9 @@ def get_app(args: argparse.Namespace, request_queue: Queue, temp_dir: str): text = request.args.get("INPUT_TEXT", "") voice = str(request.args.get("VOICE", voice)).strip() + if args.max_text_length is not None: + text = text[: args.max_text_length] + voice = voice or args.voice or DEFAULT_VOICE # Assume SSML if text begins with an angle bracket diff --git a/mimic3_http/args.py b/mimic3_http/args.py index e1e147b..7cf5e67 100644 --- a/mimic3_http/args.py +++ b/mimic3_http/args.py @@ -81,6 +81,11 @@ def get_args(argv=None) -> argparse.Namespace: default=1, help="Number of synthesis threads (default: 1)", ) + parser.add_argument( + "--max-text-length", + type=int, + help="Maximum length of input text to process (default: no limit)", + ) parser.add_argument( "--debug", action="store_true", help="Print DEBUG messages to console" ) diff --git a/mimic3_http/templates/index.html b/mimic3_http/templates/index.html index 2000bcd..4a186c3 100644 --- a/mimic3_http/templates/index.html +++ b/mimic3_http/templates/index.html @@ -54,7 +54,8 @@
- +