Add --max-text-length to mimic3-server

This commit is contained in:
Michael Hansen 2022-05-10 11:01:46 -04:00
commit 05795c5d82
3 changed files with 18 additions and 2 deletions

View file

@ -153,7 +153,11 @@ def get_app(args: argparse.Namespace, request_queue: Queue, temp_dir: str):
@app.route("/") @app.route("/")
async def app_index(): async def app_index():
"""Main page.""" """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"]) @app.route("/api/tts", methods=["GET", "POST"])
async def app_tts() -> Response: 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" assert text, "No text provided"
if args.max_text_length is not None:
text = text[: args.max_text_length]
# Cache settings # Cache settings
no_cache_str = request.args.get("noCache", "") no_cache_str = request.args.get("noCache", "")
no_cache = _to_bool(no_cache_str) 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", "") text = request.args.get("INPUT_TEXT", "")
voice = str(request.args.get("VOICE", voice)).strip() 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 voice = voice or args.voice or DEFAULT_VOICE
# Assume SSML if text begins with an angle bracket # Assume SSML if text begins with an angle bracket

View file

@ -81,6 +81,11 @@ def get_args(argv=None) -> argparse.Namespace:
default=1, default=1,
help="Number of synthesis threads (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( parser.add_argument(
"--debug", action="store_true", help="Print DEBUG messages to console" "--debug", action="store_true", help="Print DEBUG messages to console"
) )

View file

@ -54,7 +54,8 @@
</div> </div>
<div class="row mt-3"> <div class="row mt-3">
<div class="col"> <div class="col">
<textarea id="text" placeholder="Type here..." class="form-control" rows="3" name="text" alt="Text to generate speech from" maxlength="5000"></textarea> <textarea id="text" placeholder="Type here..." class="form-control" rows="3" name="text" alt="Text to generate speech from"
{% if max_text_length is not none: %}maxlength="{{ max_text_length }}"{% endif %}></textarea>
</div> </div>
<div class="col-auto"> <div class="col-auto">
<button id="speak-button" name="speak" class="btn btn-lg btn-primary" alt="Generate speech">Speak</button> <button id="speak-button" name="speak" class="btn btn-lg btn-primary" alt="Generate speech">Speak</button>