|
import json |
|
import os |
|
import subprocess |
|
|
|
def generate_html_output(data, repository_path): |
|
with open('speakers.md', 'a') as file: |
|
for speaker_id, speaker_info in data.items(): |
|
out_path = f"{repository_path}/samples/{speaker_id}.wav" |
|
age = speaker_info['age'] |
|
gender = speaker_info['gender'] |
|
if gender == 'F': |
|
gender = 'female' |
|
elif gender == "M": |
|
gender = 'male' |
|
accents = speaker_info['accents'] |
|
region = speaker_info['region'] |
|
|
|
file.write(f"<p>VCTK_{speaker_id}: {age} year old {gender}, {accents} accent ({region})<audio controls><source src=\"{out_path}\" type=\"audio/wav\"></audio> </p>\n") |
|
|
|
|
|
|
|
data = { |
|
"p237": {"age": 22, "gender": "M", "accents": "Scottish", "region": "Fife"}, |
|
"p241": {"age": 21, "gender": "M", "accents": "Scottish", "region": "Perth"}, |
|
"p245": {"age": 25, "gender": "M", "accents": "Irish", "region": "Dublin"}, |
|
"p246": {"age": 22, "gender": "M", "accents": "Scottish", "region": "Selkirk"}, |
|
"p247": {"age": 22, "gender": "M", "accents": "Scottish", "region": "Argyll"}, |
|
"p252": {"age": 22, "gender": "M", "accents": "Scottish", "region": "Edinburgh"}, |
|
"p255": {"age": 19, "gender": "M", "accents": "Scottish", "region": "Galloway"}, |
|
"p260": {"age": 21, "gender": "M", "accents": "Scottish", "region": "Orkney"}, |
|
"p263": {"age": 22, "gender": "M", "accents": "Scottish", "region": "Aberdeen"}, |
|
"p271": {"age": 19, "gender": "M", "accents": "Scottish", "region": "Fife"}, |
|
"p272": {"age": 23, "gender": "M", "accents": "Scottish", "region": "Edinburgh"}, |
|
"p275": {"age": 23, "gender": "M", "accents": "Scottish", "region": "Midlothian"}, |
|
"p281": {"age": 29, "gender": "M", "accents": "Scottish", "region": "Edinburgh"}, |
|
"p284": {"age": 20, "gender": "M", "accents": "Scottish", "region": "Fife"}, |
|
"p285": {"age": 21, "gender": "M", "accents": "Scottish", "region": "Edinburgh"}, |
|
"p292": {"age": 23, "gender": "M", "accents": "NorthernIrish", "region": "Belfast"}, |
|
"p298": {"age": 19, "gender": "M", "accents": "Irish", "region": "Tipperary"}, |
|
"p304": {"age": 22, "gender": "M", "accents": "NorthernIrish", "region": "Belfast"}, |
|
"p326": {"age": 26, "gender": "M", "accents": "Australian English", "region": "Sydney"}, |
|
"p364": {"age": 23, "gender": "M", "accents": "Irish", "region": "Donegal"}, |
|
"p374": {"age": 28, "gender": "M", "accents": "Australian English", "region": "The Outback"}, |
|
} |
|
|
|
|
|
json_data = json.dumps(data, indent=2) |
|
|
|
|
|
with open('speakers-log.json', 'w') as file: |
|
file.write(json_data) |
|
|
|
|
|
command = "tts --model_path checkpoint_85000.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) |
|
|
|
|
|
with open('speakers.md', 'w') as file: |
|
for speaker_idx in speaker_indices: |
|
|
|
speaker_id = speaker_idx.replace('VCTK_', '') |
|
|
|
|
|
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_85000.pth --language_idx en --config_path config.json --speaker_idx \"VCTK_{speaker_id}\" --out_path {out_path}" |
|
|
|
|
|
os.system(tts_command) |
|
|
|
|
|
generate_html_output({speaker_id: speaker_id_json}, "https://huggingface.co/voices/VCTK_European_English_Males/resolve/main") |
|
|