VCTK_British_English_Males / prepare_model.py
jvision's picture
Updating speaker labels
b0e487c
import json
import os
import subprocess
# Load the data from the provided dictionary
data = {
"VCTK_p226": {"age": 22, "gender": "M", "accents": "English", "region": "Surrey"},
"VCTK_p227": {"age": 38, "gender": "M", "accents": "English", "region": "Cumbria"},
"VCTK_p232": {"age": 23, "gender": "M", "accents": "English", "region": "Southern England"},
"VCTK_p243": {"age": 22, "gender": "M", "accents": "English", "region": "London"},
"VCTK_p254": {"age": 21, "gender": "M", "accents": "English", "region": "Surrey"},
"VCTK_p256": {"age": 24, "gender": "M", "accents": "English", "region": "Birmingham"},
"VCTK_p258": {"age": 22, "gender": "M", "accents": "English", "region": "Southern England"},
"VCTK_p259": {"age": 23, "gender": "M", "accents": "English", "region": "Nottingham"},
"VCTK_p270": {"age": 21, "gender": "M", "accents": "English", "region": "Yorkshire"},
"VCTK_p273": {"age": 23, "gender": "M", "accents": "English", "region": "Suffolk"},
"VCTK_p274": {"age": 22, "gender": "M", "accents": "English", "region": "Essex"},
"VCTK_p278": {"age": 22, "gender": "M", "accents": "English", "region": "Cheshire"},
"VCTK_p279": {"age": 23, "gender": "M", "accents": "English", "region": "Leicester"},
"VCTK_p286": {"age": 23, "gender": "M", "accents": "English", "region": "Newcastle"},
"VCTK_p287": {"age": 23, "gender": "M", "accents": "English", "region": "York"}
}
# Convert the data to JSON format
json_data = json.dumps(data, indent=2)
# Save the JSON data to a file
with open('speakers-log.json', 'w') as file:
file.write(json_data)
# Run the TTS command to get the speaker indices
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)
# Parse the JSON output into a Python dictionary
speaker_indices = eval(output)
# Load the speaker IDs from speakers.json
with open('speakers-log.json', 'r') as file:
speaker_ids = json.load(file)
for speaker_idx in speaker_indices:
# # Remove the 'VCTK_' prefix
speaker_id = speaker_idx
# speaker_id = speaker_idx.replace('VCTK_', '')
# Lookup the speaker ID in the loaded speaker IDs
if speaker_id in speaker_ids:
speaker_id_json = speaker_ids[speaker_id]
else:
continue
# # Generate the TTS command to create the audio file
# text = f"Hello, I am from {speaker_id_json['region']}. I hope that you will select my voice for your project. Thank you."
# # make samples directory if it doesn't exist
# 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}"
# Execute the TTS command
# os.system(tts_command)