Skip to content

Commit 5c047cf

Browse files
committed
Ensure tts CLI tool readme and usage help is in sync
1 parent 0b95b88 commit 5c047cf

File tree

4 files changed

+202
-108
lines changed

4 files changed

+202
-108
lines changed

README.md

Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -294,99 +294,123 @@ api.tts_with_vc_to_file(
294294
```
295295

296296
### Command-line `tts`
297+
298+
<!-- begin-tts-readme -->
299+
300+
Synthesize speech on command line.
301+
302+
You can either use your trained model or choose a model from the provided list.
303+
304+
If you don't specify any models, then it uses LJSpeech based English model.
305+
297306
#### Single Speaker Models
298307

299308
- List provided models:
300309

301-
```
302-
$ tts --list_models
303-
```
310+
```
311+
$ tts --list_models
312+
```
313+
304314
- Get model info (for both tts_models and vocoder_models):
305-
- Query by type/name:
306-
The model_info_by_name uses the name as it from the --list_models.
307-
```
308-
$ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
309-
```
310-
For example:
311-
312-
```
313-
$ tts --model_info_by_name tts_models/tr/common-voice/glow-tts
314-
```
315-
```
316-
$ tts --model_info_by_name vocoder_models/en/ljspeech/hifigan_v2
317-
```
318-
- Query by type/idx:
319-
The model_query_idx uses the corresponding idx from --list_models.
320-
```
321-
$ tts --model_info_by_idx "<model_type>/<model_query_idx>"
322-
```
323-
For example:
324-
325-
```
326-
$ tts --model_info_by_idx tts_models/3
327-
```
328315

329-
- Run TTS with default models:
316+
- Query by type/name:
317+
The model_info_by_name uses the name as it from the --list_models.
318+
```
319+
$ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
320+
```
321+
For example:
322+
```
323+
$ tts --model_info_by_name tts_models/tr/common-voice/glow-tts
324+
$ tts --model_info_by_name vocoder_models/en/ljspeech/hifigan_v2
325+
```
326+
- Query by type/idx:
327+
The model_query_idx uses the corresponding idx from --list_models.
330328
331329
```
332-
$ tts --text "Text for TTS" --out_path output/path/speech.wav
330+
$ tts --model_info_by_idx "<model_type>/<model_query_idx>"
333331
```
334332
335-
- Run a TTS model with its default vocoder model:
333+
For example:
336334
337335
```
338-
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
336+
$ tts --model_info_by_idx tts_models/3
339337
```
340-
For example:
341338
339+
- Query info for model info by full name:
342340
```
343-
$ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output/path/speech.wav
341+
$ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
344342
```
345343
346-
- Run with specific TTS and vocoder models from the list:
344+
- Run TTS with default models:
347345
348-
```
349-
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --vocoder_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
350-
```
346+
```
347+
$ tts --text "Text for TTS" --out_path output/path/speech.wav
348+
```
349+
350+
- Run a TTS model with its default vocoder model:
351+
352+
```
353+
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
354+
```
351355
352356
For example:
353357
354-
```
355-
$ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --vocoder_name "vocoder_models/en/ljspeech/univnet" --out_path output/path/speech.wav
356-
```
358+
```
359+
$ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output/path/speech.wav
360+
```
361+
362+
- Run with specific TTS and vocoder models from the list:
363+
364+
```
365+
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --vocoder_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
366+
```
367+
368+
For example:
357369
370+
```
371+
$ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --vocoder_name "vocoder_models/en/ljspeech/univnet" --out_path output/path/speech.wav
372+
```
358373
359374
- Run your own TTS model (Using Griffin-Lim Vocoder):
360375
361-
```
362-
$ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
363-
```
376+
```
377+
$ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
378+
```
364379
365380
- Run your own TTS and Vocoder models:
366-
```
367-
$ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
368-
--vocoder_path path/to/vocoder.pth --vocoder_config_path path/to/vocoder_config.json
369-
```
381+
382+
```
383+
$ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
384+
--vocoder_path path/to/vocoder.pth --vocoder_config_path path/to/vocoder_config.json
385+
```
370386
371387
#### Multi-speaker Models
372388
373389
- List the available speakers and choose a <speaker_id> among them:
374390
375-
```
376-
$ tts --model_name "<language>/<dataset>/<model_name>" --list_speaker_idxs
377-
```
391+
```
392+
$ tts --model_name "<language>/<dataset>/<model_name>" --list_speaker_idxs
393+
```
378394
379395
- Run the multi-speaker TTS model with the target speaker ID:
380396
381-
```
382-
$ tts --text "Text for TTS." --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --speaker_idx <speaker_id>
383-
```
397+
```
398+
$ tts --text "Text for TTS." --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --speaker_idx <speaker_id>
399+
```
384400
385401
- Run your own multi-speaker TTS model:
386402
387-
```
388-
$ tts --text "Text for TTS" --out_path output/path/speech.wav --model_path path/to/model.pth --config_path path/to/config.json --speakers_file_path path/to/speaker.json --speaker_idx <speaker_id>
389-
```
403+
```
404+
$ tts --text "Text for TTS" --out_path output/path/speech.wav --model_path path/to/model.pth --config_path path/to/config.json --speakers_file_path path/to/speaker.json --speaker_idx <speaker_id>
405+
```
406+
407+
### Voice Conversion Models
408+
409+
```
410+
$ tts --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --source_wav <path/to/speaker/wav> --target_wav <path/to/reference/wav>
411+
```
412+
413+
<!-- end-tts-readme -->
390414
391415
## Directory Structure
392416
```

TTS/bin/synthesize.py

Lines changed: 82 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,104 +12,133 @@
1212
from TTS.utils.manage import ModelManager
1313
from TTS.utils.synthesizer import Synthesizer
1414

15-
16-
def str2bool(v):
17-
if isinstance(v, bool):
18-
return v
19-
if v.lower() in ("yes", "true", "t", "y", "1"):
20-
return True
21-
if v.lower() in ("no", "false", "f", "n", "0"):
22-
return False
23-
raise argparse.ArgumentTypeError("Boolean value expected.")
24-
25-
26-
def main():
27-
description = """Synthesize speech on command line.
15+
description = """
16+
Synthesize speech on command line.
2817
2918
You can either use your trained model or choose a model from the provided list.
3019
3120
If you don't specify any models, then it uses LJSpeech based English model.
3221
33-
## Example Runs
34-
35-
### Single Speaker Models
22+
#### Single Speaker Models
3623
3724
- List provided models:
3825
26+
```
27+
$ tts --list_models
28+
```
29+
30+
- Get model info (for both tts_models and vocoder_models):
31+
32+
- Query by type/name:
33+
The model_info_by_name uses the name as it from the --list_models.
3934
```
40-
$ tts --list_models
35+
$ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
4136
```
42-
43-
- Query info for model info by idx:
37+
For example:
38+
```
39+
$ tts --model_info_by_name tts_models/tr/common-voice/glow-tts
40+
$ tts --model_info_by_name vocoder_models/en/ljspeech/hifigan_v2
41+
```
42+
- Query by type/idx:
43+
The model_query_idx uses the corresponding idx from --list_models.
4444
4545
```
4646
$ tts --model_info_by_idx "<model_type>/<model_query_idx>"
4747
```
4848
49-
- Query info for model info by full name:
49+
For example:
50+
51+
```
52+
$ tts --model_info_by_idx tts_models/3
53+
```
5054
55+
- Query info for model info by full name:
5156
```
5257
$ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
5358
```
5459
5560
- Run TTS with default models:
5661
57-
```
58-
$ tts --text "Text for TTS"
59-
```
62+
```
63+
$ tts --text "Text for TTS" --out_path output/path/speech.wav
64+
```
6065
6166
- Run a TTS model with its default vocoder model:
6267
63-
```
64-
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>
65-
```
68+
```
69+
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
70+
```
71+
72+
For example:
73+
74+
```
75+
$ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output/path/speech.wav
76+
```
6677
6778
- Run with specific TTS and vocoder models from the list:
6879
69-
```
70-
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --vocoder_name "<model_type>/<language>/<dataset>/<model_name>" --output_path
71-
```
80+
```
81+
$ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --vocoder_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
82+
```
83+
84+
For example:
85+
86+
```
87+
$ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --vocoder_name "vocoder_models/en/ljspeech/univnet" --out_path output/path/speech.wav
88+
```
7289
7390
- Run your own TTS model (Using Griffin-Lim Vocoder):
7491
75-
```
76-
$ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
77-
```
92+
```
93+
$ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
94+
```
7895
7996
- Run your own TTS and Vocoder models:
80-
```
81-
$ tts --text "Text for TTS" --model_path path/to/config.json --config_path path/to/model.pth --out_path output/path/speech.wav
82-
--vocoder_path path/to/vocoder.pth --vocoder_config_path path/to/vocoder_config.json
83-
```
8497
85-
### Multi-speaker Models
98+
```
99+
$ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
100+
--vocoder_path path/to/vocoder.pth --vocoder_config_path path/to/vocoder_config.json
101+
```
86102
87-
- List the available speakers and choose as <speaker_id> among them:
103+
#### Multi-speaker Models
88104
89-
```
90-
$ tts --model_name "<language>/<dataset>/<model_name>" --list_speaker_idxs
91-
```
105+
- List the available speakers and choose a <speaker_id> among them:
106+
107+
```
108+
$ tts --model_name "<language>/<dataset>/<model_name>" --list_speaker_idxs
109+
```
92110
93111
- Run the multi-speaker TTS model with the target speaker ID:
94112
95-
```
96-
$ tts --text "Text for TTS." --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --speaker_idx <speaker_id>
97-
```
113+
```
114+
$ tts --text "Text for TTS." --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --speaker_idx <speaker_id>
115+
```
98116
99117
- Run your own multi-speaker TTS model:
100118
101-
```
102-
$ tts --text "Text for TTS" --out_path output/path/speech.wav --model_path path/to/config.json --config_path path/to/model.pth --speakers_file_path path/to/speaker.json --speaker_idx <speaker_id>
103-
```
119+
```
120+
$ tts --text "Text for TTS" --out_path output/path/speech.wav --model_path path/to/model.pth --config_path path/to/config.json --speakers_file_path path/to/speaker.json --speaker_idx <speaker_id>
121+
```
104122
105123
### Voice Conversion Models
106124
107-
```
108-
$ tts --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --source_wav <path/to/speaker/wav> --target_wav <path/to/reference/wav>
109-
```
110-
"""
111-
# We remove Markdown code formatting programmatically here to allow us to copy-and-paste from main README to keep
112-
# documentation in sync more easily.
125+
```
126+
$ tts --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --source_wav <path/to/speaker/wav> --target_wav <path/to/reference/wav>
127+
```
128+
"""
129+
130+
131+
def str2bool(v):
132+
if isinstance(v, bool):
133+
return v
134+
if v.lower() in ("yes", "true", "t", "y", "1"):
135+
return True
136+
if v.lower() in ("no", "false", "f", "n", "0"):
137+
return False
138+
raise argparse.ArgumentTypeError("Boolean value expected.")
139+
140+
141+
def main():
113142
parser = argparse.ArgumentParser(
114143
description=description.replace(" ```\n", ""),
115144
formatter_class=RawTextHelpFormatter,

scripts/sync_readme.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import argparse
2+
from pathlib import Path
3+
4+
5+
def replace_between_markers(content, marker: str, replacement: str) -> str:
6+
start_marker = f"<!-- begin-{marker} -->\n\n"
7+
end_marker = f"\n\n<!-- end-{marker} -->\n"
8+
start_index = content.index(start_marker) + len(start_marker)
9+
end_index = content.index(end_marker)
10+
content = content[:start_index] + replacement + content[end_index:]
11+
return content
12+
13+
14+
def sync_readme():
15+
ap = argparse.ArgumentParser()
16+
ap.add_argument("--check", action="store_true", default=False)
17+
args = ap.parse_args()
18+
readme_path = Path(__file__).parent.parent / "README.md"
19+
orig_content = readme_path.read_text()
20+
from TTS.bin.synthesize import description
21+
22+
new_content = replace_between_markers(orig_content, "tts-readme", description.strip())
23+
if args.check:
24+
if orig_content != new_content:
25+
print("README.md is out of sync; please edit TTS/bin/TTS_README.md and run scripts/sync_readme.py")
26+
exit(42)
27+
readme_path.write_text(new_content)
28+
print("Updated README.md")
29+
30+
31+
if __name__ == "__main__":
32+
sync_readme()

0 commit comments

Comments
 (0)