|
import json |
|
import os |
|
import subprocess |
|
|
|
|
|
data = { |
|
"VCTK_p303": {"age": 24, "gender": "F", "accents": "Canadian", "region": "Toronto", "comments": ""}, |
|
"VCTK_p312": {"age": 19, "gender": "F", "accents": "Canadian", "region": "Hamilton", "comments": ""}, |
|
"VCTK_p317": {"age": 23, "gender": "F", "accents": "Canadian", "region": "Hamilton", "comments": ""}, |
|
"VCTK_p343": {"age": 27, "gender": "F", "accents": "Canadian", "region": "Alberta", "comments": ""}, |
|
"VCTK_p307": {"age": 23, "gender": "F", "accents": "Canadian", "region": "Ontario", "comments": ""}, |
|
"VCTK_p316": {"age": 20, "gender": "M", "accents": "Canadian", "region": "Alberta", "comments": ""}, |
|
"VCTK_p363": {"age": 22, "gender": "M", "accents": "Canadian", "region": "Toronto", "comments": ""}, |
|
"VCTK_p302": {"age": 20, "gender": "M", "accents": "Canadian", "region": "Montreal", "comments": ""} |
|
} |
|
|
|
|
|
|
|
json_data = json.dumps(data, indent=2) |
|
|
|
|
|
with open('speakers-log.json', 'w') as file: |
|
file.write(json_data) |
|
|
|
|
|
command = "tts --model_path checkpoint_40000.pth --config_path config.json --list_speaker_idxs | grep -vE '^(\s*\||\s*>|\s*$)'" |
|
output = subprocess.check_output(command, shell=True, text=True) |
|
|
|
|
|
speaker_indices = eval(output) |
|
|
|
|
|
with open('speakers-log.json', 'r') as file: |
|
speaker_ids = json.load(file) |
|
|
|
|
|
for speaker_idx in speaker_indices: |
|
|
|
speaker_id = speaker_idx |
|
|
|
|
|
|
|
if speaker_id in speaker_ids: |
|
speaker_id_json = speaker_ids[speaker_id] |
|
else: |
|
continue |
|
|
|
|
|
text = f"Hello, I am from {speaker_id_json['region']}. I hope that you will select my voice for your project. Thank you." |
|
|
|
if not os.path.exists("samples"): |
|
os.makedirs("samples") |
|
|
|
out_path = f"samples/{speaker_id}.wav" |
|
tts_command = f"tts --text \"{text}\" --model_path checkpoint_40000.pth --language_idx en --config_path config.json --speaker_idx \"{speaker_id}\" --out_path {out_path}" |
|
|
|
|
|
os.system(tts_command) |