Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -100,8 +100,45 @@ phonemizers = dict(
|
|
| 100 |
j=Katsu(),
|
| 101 |
)
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
def resolve_voices(voice, warn=True):
|
| 104 |
-
if not isinstance(voice, str):
|
| 105 |
return ['af']
|
| 106 |
voices = voice.lower().replace('/', '_').replace(' ', '+').replace(',', '+').split('+')
|
| 107 |
if warn:
|
|
@@ -153,43 +190,6 @@ VOCAB = get_vocab()
|
|
| 153 |
def tokenize(ps):
|
| 154 |
return [i for i in map(VOCAB.get, ps) if i is not None]
|
| 155 |
|
| 156 |
-
# Starred voices are more stable
|
| 157 |
-
CHOICES = {
|
| 158 |
-
'🇺🇸 🚺 American Female ⭐': 'af',
|
| 159 |
-
'🇺🇸 🚺 Bella ⭐': 'af_bella',
|
| 160 |
-
'🇺🇸 🚺 Nicole ⭐': 'af_nicole',
|
| 161 |
-
'🇺🇸 🚺 Sarah ⭐': 'af_sarah',
|
| 162 |
-
'🇺🇸 🚺 American Female 1': 'af_1',
|
| 163 |
-
'🇺🇸 🚺 Alloy': 'af_alloy',
|
| 164 |
-
'🇺🇸 🚺 Jessica': 'af_jessica',
|
| 165 |
-
'🇺🇸 🚺 Nova': 'af_nova',
|
| 166 |
-
'🇺🇸 🚺 River': 'af_river',
|
| 167 |
-
'🇺🇸 🚺 Sky': 'af_sky',
|
| 168 |
-
'🇺🇸 🚹 Michael ⭐': 'am_michael',
|
| 169 |
-
'🇺🇸 🚹 Adam': 'am_adam',
|
| 170 |
-
'🇺🇸 🚹 Echo': 'am_echo',
|
| 171 |
-
'🇺🇸 🚹 Eric': 'am_eric',
|
| 172 |
-
'🇺🇸 🚹 Liam': 'am_liam',
|
| 173 |
-
'🇺🇸 🚹 Onyx': 'am_onyx',
|
| 174 |
-
'🇬🇧 🚺 British Female 0': 'bf_0',
|
| 175 |
-
'🇬🇧 🚺 British Female 1': 'bf_1',
|
| 176 |
-
'🇬🇧 🚺 British Female 2': 'bf_2',
|
| 177 |
-
'🇬🇧 🚺 British Female 3': 'bf_3',
|
| 178 |
-
'🇬🇧 🚺 Alice': 'bf_alice',
|
| 179 |
-
'🇬🇧 🚺 Lily': 'bf_lily',
|
| 180 |
-
'🇬🇧 🚹 British Male 0': 'bm_0',
|
| 181 |
-
'🇬🇧 🚹 British Male 1': 'bm_1',
|
| 182 |
-
'🇬🇧 🚹 Daniel': 'bm_daniel',
|
| 183 |
-
'🇬🇧 🚹 Fable': 'bm_fable',
|
| 184 |
-
'🇬🇧 🚹 George': 'bm_george',
|
| 185 |
-
'🇬🇧 🚹 Lewis': 'bm_lewis',
|
| 186 |
-
'🇯🇵 🚺 Japanese Female ⭐': 'jf_0',
|
| 187 |
-
'🇯🇵 🚺 Japanese Female 1': 'jf_1',
|
| 188 |
-
'🇯🇵 🚺 Japanese Female 2': 'jf_2',
|
| 189 |
-
'🇯🇵 🚺 Japanese Female 3': 'jf_3',
|
| 190 |
-
}
|
| 191 |
-
VOICES = {device: {k: torch.load(os.path.join(snapshot, 'voicepacks', f'{k}.pt'), weights_only=True).to(device) for k in CHOICES.values()} for device in models}
|
| 192 |
-
|
| 193 |
SAMPLE_RATE = 24000
|
| 194 |
|
| 195 |
@torch.no_grad()
|
|
@@ -276,9 +276,6 @@ USE_GPU_INFOS = {
|
|
| 276 |
def change_use_gpu(value):
|
| 277 |
return gr.Dropdown(USE_GPU_CHOICES, value=value, label='Hardware', info=USE_GPU_INFOS[value], interactive=CUDA_AVAILABLE)
|
| 278 |
|
| 279 |
-
def update_voice(voice, btn):
|
| 280 |
-
return f'{voice}+{btn}' if voice.startswith(btn[:2]) else btn
|
| 281 |
-
|
| 282 |
with gr.Blocks() as basic_tts:
|
| 283 |
with gr.Row():
|
| 284 |
with gr.Column():
|
|
@@ -319,7 +316,7 @@ with gr.Blocks() as basic_tts:
|
|
| 319 |
for j in range(4):
|
| 320 |
with gr.Column():
|
| 321 |
btn = gr.Button(list(CHOICES.values())[i*4+j], variant='primary' if i*4+j < 10 else 'secondary')
|
| 322 |
-
btn.click(
|
| 323 |
voice.change(lambda v, b: gr.Button(b, variant='primary' if v.startswith(b[:2]) else 'secondary'), inputs=[voice, btn], outputs=[btn])
|
| 324 |
text.submit(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
|
| 325 |
generate_btn.click(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
|
|
|
|
| 100 |
j=Katsu(),
|
| 101 |
)
|
| 102 |
|
| 103 |
+
# Starred voices are more stable
|
| 104 |
+
CHOICES = {
|
| 105 |
+
'🇺🇸 🚺 American Female ⭐': 'af',
|
| 106 |
+
'🇺🇸 🚺 Bella ⭐': 'af_bella',
|
| 107 |
+
'🇺🇸 🚺 Nicole ⭐': 'af_nicole',
|
| 108 |
+
'🇺🇸 🚺 Sarah ⭐': 'af_sarah',
|
| 109 |
+
'🇺🇸 🚺 American Female 1': 'af_1',
|
| 110 |
+
'🇺🇸 🚺 Alloy': 'af_alloy',
|
| 111 |
+
'🇺🇸 🚺 Jessica': 'af_jessica',
|
| 112 |
+
'🇺🇸 🚺 Nova': 'af_nova',
|
| 113 |
+
'🇺🇸 🚺 River': 'af_river',
|
| 114 |
+
'🇺🇸 🚺 Sky': 'af_sky',
|
| 115 |
+
'🇺🇸 🚹 Michael ⭐': 'am_michael',
|
| 116 |
+
'🇺🇸 🚹 Adam': 'am_adam',
|
| 117 |
+
'🇺🇸 🚹 Echo': 'am_echo',
|
| 118 |
+
'🇺🇸 🚹 Eric': 'am_eric',
|
| 119 |
+
'🇺🇸 🚹 Liam': 'am_liam',
|
| 120 |
+
'🇺🇸 🚹 Onyx': 'am_onyx',
|
| 121 |
+
'🇬🇧 🚺 British Female 0': 'bf_0',
|
| 122 |
+
'🇬🇧 🚺 British Female 1': 'bf_1',
|
| 123 |
+
'🇬🇧 🚺 British Female 2': 'bf_2',
|
| 124 |
+
'🇬🇧 🚺 British Female 3': 'bf_3',
|
| 125 |
+
'🇬🇧 🚺 Alice': 'bf_alice',
|
| 126 |
+
'🇬🇧 🚺 Lily': 'bf_lily',
|
| 127 |
+
'🇬🇧 🚹 British Male 0': 'bm_0',
|
| 128 |
+
'🇬🇧 🚹 British Male 1': 'bm_1',
|
| 129 |
+
'🇬🇧 🚹 Daniel': 'bm_daniel',
|
| 130 |
+
'🇬🇧 🚹 Fable': 'bm_fable',
|
| 131 |
+
'🇬🇧 🚹 George': 'bm_george',
|
| 132 |
+
'🇬🇧 🚹 Lewis': 'bm_lewis',
|
| 133 |
+
'🇯🇵 🚺 Japanese Female ⭐': 'jf_0',
|
| 134 |
+
'🇯🇵 🚺 Japanese Female 1': 'jf_1',
|
| 135 |
+
'🇯🇵 🚺 Japanese Female 2': 'jf_2',
|
| 136 |
+
'🇯🇵 🚺 Japanese Female 3': 'jf_3',
|
| 137 |
+
}
|
| 138 |
+
VOICES = {device: {k: torch.load(os.path.join(snapshot, 'voicepacks', f'{k}.pt'), weights_only=True).to(device) for k in CHOICES.values()} for device in models}
|
| 139 |
+
|
| 140 |
def resolve_voices(voice, warn=True):
|
| 141 |
+
if not isinstance(voice, str) or voice == list(CHOICES.keys())[0]:
|
| 142 |
return ['af']
|
| 143 |
voices = voice.lower().replace('/', '_').replace(' ', '+').replace(',', '+').split('+')
|
| 144 |
if warn:
|
|
|
|
| 190 |
def tokenize(ps):
|
| 191 |
return [i for i in map(VOCAB.get, ps) if i is not None]
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
SAMPLE_RATE = 24000
|
| 194 |
|
| 195 |
@torch.no_grad()
|
|
|
|
| 276 |
def change_use_gpu(value):
|
| 277 |
return gr.Dropdown(USE_GPU_CHOICES, value=value, label='Hardware', info=USE_GPU_INFOS[value], interactive=CUDA_AVAILABLE)
|
| 278 |
|
|
|
|
|
|
|
|
|
|
| 279 |
with gr.Blocks() as basic_tts:
|
| 280 |
with gr.Row():
|
| 281 |
with gr.Column():
|
|
|
|
| 316 |
for j in range(4):
|
| 317 |
with gr.Column():
|
| 318 |
btn = gr.Button(list(CHOICES.values())[i*4+j], variant='primary' if i*4+j < 10 else 'secondary')
|
| 319 |
+
btn.click(lambda v, b: f'{v}+{b}' if v.startswith(b[:2]) else b, inputs=[voice, btn], outputs=[voice])
|
| 320 |
voice.change(lambda v, b: gr.Button(b, variant='primary' if v.startswith(b[:2]) else 'secondary'), inputs=[voice, btn], outputs=[btn])
|
| 321 |
text.submit(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
|
| 322 |
generate_btn.click(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
|