File size: 3,909 Bytes
46583ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import json
import os
import subprocess

# Load the data from the provided dictionary
data = {
    "VCTK_p283": {
        "age": 24,
        "gender": "F",
        "accents": "Irish",
        "region": "Cork"
    },
    "VCTK_p266": {
        "age": 22,
        "gender": "F",
        "accents": "Irish",
        "region": "Athlone"
    },
    "VCTK_p288": {
        "age": 22,
        "gender": "F",
        "accents": "Irish",
        "region": "Dublin"
    },
    "VCTK_p295": {
        "age": 23,
        "gender": "F",
        "accents": "Irish",
        "region": "Dublin"
    },
    "VCTK_p293": {
        "age": 22,
        "gender": "F",
        "accents": "NorthernIrish",
        "region": "Belfast"
    },
    "VCTK_p238": {
        "age": 22,
        "gender": "F",
        "accents": "NorthernIrish",
        "region": "Belfast"
    },
    "VCTK_p261": {
        "age": 26,
        "gender": "F",
        "accents": "NorthernIrish",
        "region": "Belfast"
    },
    "VCTK_p351": {
        "age": 21,
        "gender": "F",
        "accents": "NorthernIrish",
        "region": "Derry"
    },
    "VCTK_p249": {
        "age": 22,
        "gender": "F",
        "accents": "Scottish",
        "region": "Aberdeen"
    },
    "VCTK_p234": {
        "age": 22,
        "gender": "F",
        "accents": "Scottish",
        "region": "West Dumfries"
    },
    "VCTK_p262": {
        "age": 23,
        "gender": "F",
        "accents": "Scottish",
        "region": "Edinburgh"
    },
    "VCTK_p264": {
        "age": 23,
        "gender": "F",
        "accents": "Scottish",
        "region": "West Lothian"
    },
    "VCTK_p265": {
        "age": 23,
        "gender": "F",
        "accents": "Scottish",
        "region": "Ross"
    },
    "VCTK_p253": {
        "age": 22,
        "gender": "F",
        "accents": "Welsh",
        "region": "Cardiff"
    },
    "VCTK_p313": {
        "age": 24,
        "gender": "F",
        "accents": "Irish",
        "region": "County Down"
    },
    "VCTK_p340": {
        "age": 18,
        "gender": "F",
        "accents": "Irish",
        "region": "Dublin"
    },
    "VCTK_p335": {
        "age": 25,
        "gender": "F",
        "accents": "NewZealand",
        "region": "English"
    },
    "VCTK_p280": {
        "age": 25,
        "gender": "F",
        "accents": "France",
        "region": "France"
    }
}

# 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 \"{speaker_id}\" --out_path {out_path}"

    # Execute the TTS command
    os.system(tts_command)