|
1 | 1 | #!flask/bin/python
|
| 2 | + |
| 3 | +"""TTS demo server.""" |
| 4 | + |
2 | 5 | import argparse
|
3 | 6 | import io
|
4 | 7 | import json
|
|
13 | 16 | try:
|
14 | 17 | from flask import Flask, render_template, render_template_string, request, send_file
|
15 | 18 | except ImportError as e:
|
16 |
| - raise ImportError("Server requires requires flask, use `pip install coqui-tts[server]`.") from e |
| 19 | + msg = "Server requires requires flask, use `pip install coqui-tts[server]`" |
| 20 | + raise ImportError(msg) from e |
17 | 21 |
|
18 | 22 | from TTS.config import load_config
|
19 | 23 | from TTS.utils.generic_utils import ConsoleFormatter, setup_logger
|
|
24 | 28 | setup_logger("TTS", level=logging.INFO, screen=True, formatter=ConsoleFormatter())
|
25 | 29 |
|
26 | 30 |
|
27 |
| -def create_argparser(): |
28 |
| - def convert_boolean(x): |
29 |
| - return x.lower() in ["true", "1", "yes"] |
30 |
| - |
| 31 | +def create_argparser() -> argparse.ArgumentParser: |
31 | 32 | parser = argparse.ArgumentParser()
|
32 | 33 | parser.add_argument(
|
33 | 34 | "--list_models",
|
34 |
| - type=convert_boolean, |
35 |
| - nargs="?", |
36 |
| - const=True, |
37 |
| - default=False, |
| 35 | + action="store_true", |
38 | 36 | help="list available pre-trained tts and vocoder models.",
|
39 | 37 | )
|
40 | 38 | parser.add_argument(
|
@@ -62,9 +60,13 @@ def convert_boolean(x):
|
62 | 60 | parser.add_argument("--vocoder_config_path", type=str, help="Path to vocoder model config file.", default=None)
|
63 | 61 | parser.add_argument("--speakers_file_path", type=str, help="JSON file for multi-speaker model.", default=None)
|
64 | 62 | parser.add_argument("--port", type=int, default=5002, help="port to listen on.")
|
65 |
| - parser.add_argument("--use_cuda", type=convert_boolean, default=False, help="true to use CUDA.") |
66 |
| - parser.add_argument("--debug", type=convert_boolean, default=False, help="true to enable Flask debug mode.") |
67 |
| - parser.add_argument("--show_details", type=convert_boolean, default=False, help="Generate model detail page.") |
| 63 | + parser.add_argument("--use_cuda", action=argparse.BooleanOptionalAction, default=False, help="true to use CUDA.") |
| 64 | + parser.add_argument( |
| 65 | + "--debug", action=argparse.BooleanOptionalAction, default=False, help="true to enable Flask debug mode." |
| 66 | + ) |
| 67 | + parser.add_argument( |
| 68 | + "--show_details", action=argparse.BooleanOptionalAction, default=False, help="Generate model detail page." |
| 69 | + ) |
68 | 70 | return parser
|
69 | 71 |
|
70 | 72 |
|
@@ -168,17 +170,15 @@ def index():
|
168 | 170 | def details():
|
169 | 171 | if args.config_path is not None and os.path.isfile(args.config_path):
|
170 | 172 | model_config = load_config(args.config_path)
|
171 |
| - else: |
172 |
| - if args.model_name is not None: |
173 |
| - model_config = load_config(config_path) |
| 173 | + elif args.model_name is not None: |
| 174 | + model_config = load_config(config_path) |
174 | 175 |
|
175 | 176 | if args.vocoder_config_path is not None and os.path.isfile(args.vocoder_config_path):
|
176 | 177 | vocoder_config = load_config(args.vocoder_config_path)
|
| 178 | + elif args.vocoder_name is not None: |
| 179 | + vocoder_config = load_config(vocoder_config_path) |
177 | 180 | else:
|
178 |
| - if args.vocoder_name is not None: |
179 |
| - vocoder_config = load_config(vocoder_config_path) |
180 |
| - else: |
181 |
| - vocoder_config = None |
| 181 | + vocoder_config = None |
182 | 182 |
|
183 | 183 | return render_template(
|
184 | 184 | "details.html",
|
|
0 commit comments