Spaces:
Sleeping
Sleeping
File size: 12,039 Bytes
66a11c3 b6b60fb 66a11c3 820c8cb b6b60fb 529e659 41fae22 529e659 b6b60fb b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e f1b6ca6 b59e05e b6b60fb f69009a 8a2c769 34e38f2 8a2c769 b6b60fb 529e659 b6b60fb 529e659 b6b60fb f6b0f9e f1b6ca6 b6b60fb f1b6ca6 b6b60fb b59e05e b6b60fb f1b6ca6 b59e05e b6b60fb b59e05e b6b60fb b59e05e e24edc3 102ba36 7920b1c a9da7dc 7920b1c 102ba36 afa618c 102ba36 afa618c 102ba36 a8dc071 afa618c b6b60fb bcc3653 b6b60fb a9da7dc b6b60fb a9da7dc b6b60fb a9da7dc b6b60fb a9da7dc b6b60fb bcc3653 a9da7dc bcc3653 d38cf13 bcc3653 d38cf13 a9da7dc bcc3653 2fc1eca b6b60fb 8a2c769 a9da7dc 8a2c769 b6b60fb 7f5c976 9780e34 | 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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | import os
import gradio as gr
from gradio_client import Client
from test_overrides import _get_param_examples, _override_params
_DESCRIPTION = """
Proxy to [xVASynth Gradio Space](https://huggingface.co/spaces/Pendrokar/xVASynth-TTS), as that space uses a Python version that MCP does not support. You can add this TTS as a tool using the "Use via API or MCP" instructions within the footer of this page.
"""
voice_models = [
("👩 #ex04", "x_ex04"),
("🧑 #ex01", "x_ex01"),
("👱♀️ 🇬🇧 #92", "ccby_nvidia_hifi_92_F"),
("👨🦳 #6671", "ccby_nvidia_hifi_6671_M"),
]
voice_models_more = [
("👸 #ex02", "x_ex02"),
("👨🦱 #ex03", "x_ex03"),
("🧔 #6670", "ccby_nvidia_hifi_6670_M"),
("👨🦲 #9017", "ccby_nvidia_hifi_9017_M"),
("🧑 #6097", "ccby_nvidia_hifi_6097_M"),
("👩🦱 #12787", "ccby_nvidia_hifi_12787_F"),
("👵 #11614", "ccby_nv_hifi_11614_F"),
("👩🦰 #8051", "ccby_nvidia_hifi_8051_F"),
("👩🦳 #11697", "ccby_nvidia_hifi_11697_F"),
("👩🦲 #9136", "ccby_nvidia_hifi_9136_F"),
("♟ Lojban", "x_selpahi"), # v2 model for Lojban, pre- the multilingual capabilities of xVASynth v3
]
# order ranked by similarity to English due to the xVASynth's use of ARPAbet instead of IPA
languages = [
("🇺🇸 EN", "en"),
("🇩🇪 DE", "de"),
("🇪🇸 ES", "es"),
("🇮🇳 HI", "hi"),
("🇨🇳 ZH", "zh"),
]
languages_more = [
("🇳🇱 NL", "nl"),
("🇧🇷 PT", "pt"),
("🇮🇹 IT", "it"),
("🇵🇱 PL", "pl"),
("🇷🇴 RO", "ro"),
("🇸🇪 SV", "sv"),
("🇩🇰 DA", "da"),
("🇫🇮 FI", "fi"),
("🇭🇺 HU", "hu"),
("🇬🇷 EL", "el"),
("🇫🇷 FR", "fr"),
("🇷🇺 RU", "ru"),
("🇺🇦 UA", "uk"),
("🇹🇷 TR", "tr"),
("🇸🇦 AR", "ar"),
("🇯🇵 JP", "jp"),
("🇰🇷 KO", "ko"),
("🇻🇳 VI", "vi"),
("🇻🇦 LA", "la"),
("🇳🇬 YO", "yo"),
("Swahili", "sw"),
("Hausa", "ha"),
("Wolof", "wo"),
]
lojban_lang = [
# There is no ISO 639-1 for Lojban, but jb is valid
('♟ Lojban', 'jb')
]
# Translated from English by DeepMind's Gemini Pro
default_text = {
"ar": "هذا هو صوتي.",
"da": "Sådan lyder min stemme.",
"de": "So klingt meine Stimme.",
"el": "Έτσι ακούγεται η φωνή μου.",
"en": "This is what my voice sounds like.",
"es": "Así suena mi voz.",
"fi": "Näin ääneni kuulostaa.",
"fr": "Voici à quoi ressemble ma voix.",
"ha": "Wannan ne muryata ke.",
"hi": "यह मेरी आवाज़ कैसी लगती है।",
"hu": "Így hangzik a hangom.",
"it": "Così suona la mia voce.",
"jb": ".i ca'e gusni",
"jp": "これが私の声です。",
"ko": "여기 제 목소리가 어떤지 들어보세요.",
"la": "Haec est vox mea sonans.",
"nl": "Dit is hoe mijn stem klinkt.",
"pl": "Tak brzmi mój głos.",
"pt": "É assim que minha voz soa.",
"ro": "Așa sună vocea mea.",
"ru": "Вот как звучит мой голос.",
"sv": "Såhär låter min röst.",
"sw": "Baba, yetu, yetu, uliye. Mbinguni, yetu, yetu. Amiiinaa!!", #civ4
"tr": "Benim sesimin sesi böyle.",
"uk": "Ось як звучить мій голос.",
"vi": "Đây là giọng nói của tôi.",
"wo": "Ndox li neen xewnaal ma.",
"yo": "Ìyí ni ohùn mi ńlá.",
"zh": "这是我的声音。",
}
# Component defaults
input_textbox_init = {
'label': "Input Text",
'value': "This is what my voice sounds like.",
'info': "Also accepts ARPAbet symbols placed within {} brackets.",
'lines': 1,
'max_lines': 5,
'autofocus': True,
'interactive': False
}
pacing_slider_init = {
'value': 1.0,
'minimum': 0.5,
'maximum': 2.0,
'step': 0.1,
'label': "Duration",
'interactive': False
}
pitch_slider_init = {
'minimum': 0,
'maximum': 1.0,
'value': 0.5,
'step': 0.05,
'label': "Pitch",
'visible': False,
'interactive': False
}
energy_slider_init = {
'minimum': 0.1,
'maximum': 1.0,
'value': 1.0,
'step': 0.05,
'label': "Energy",
'visible': False,
'interactive': False
}
anger_slider_init = {
'minimum': 0,
'maximum': 1.0,
'value': 0,
'step': 0.05,
'label': "😠 Anger",
'info': "Tread lightly beyond 0.9",
'interactive': False
}
happy_slider_init = {
'minimum': 0,
'maximum': 1.0,
'value': 0,
'step': 0.05,
'label': "😃 Happiness",
'info': "Tread lightly beyond 0.7",
'interactive': False
}
sad_slider_init = {
'minimum': 0,
'maximum': 1.0,
'value': 0,
'step': 0.05,
'label': "😭 Sadness",
'info': "Duration increased when beyond 0.2",
'interactive': False
}
surprise_slider_init = {
'minimum': 0,
'maximum': 1.0,
'value': 0,
'step': 0.05,
'label': "😮 Surprise",
'info': "Oversaturates Happiness when beyond 0.3",
'interactive': False
}
voice_radio_init = {
'choices': [*voice_models, (f'+{len(voice_models_more)}', 'more')],
'value': "ccby_nvidia_hifi_6671_M",
'label': "Voice",
'info': "Fine-tuned voice model",
'interactive': False
}
deepmoji_checkbox_init = {
'label': "Use DeepMoji",
'info': "Auto adjust emotional values for English",
'value': True,
'interactive': False
}
class BlocksDemo:
def __init__(self):
self.block = self.create_interface()
def create_interface(self):
with gr.Blocks(css=".arpabet {background-color: gray; border-radius: 5px; font-size: 120%; padding: 0 0.1em; margin: 0 0.1em; text-align: center}") as demo:
gr.Markdown("# xVASynth TTS - MCP Proxy")
gr.Markdown(value=_DESCRIPTION)
with gr.Row(): # Main row for inputs and language selection
with gr.Column(): # Input column
input_textbox = gr.Textbox(**input_textbox_init)
language_radio = gr.Radio([*languages, *languages_more, *lojban_lang], interactive=False)
with gr.Row():
with gr.Column():
en_examples_dropdown = gr.Dropdown(interactive=False)
with gr.Column():
pacing_slider = gr.Slider(**pacing_slider_init)
with gr.Column(): # Control column
voice_radio = gr.Radio([*voice_models, *voice_models_more], interactive=False)
pitch_slider = gr.Slider(**pitch_slider_init)
energy_slider = gr.Slider(**energy_slider_init)
with gr.Row(): # Main row for inputs and language selection
with gr.Column(): # Input column
anger_slider = gr.Slider(**anger_slider_init)
sad_slider = gr.Slider(**sad_slider_init)
with gr.Column(): # Input column
happy_slider = gr.Slider(**happy_slider_init)
surprise_slider = gr.Slider(**surprise_slider_init)
deepmoji_checkbox = gr.Checkbox(**deepmoji_checkbox_init)
gen_audio = gr.Button("generate", "primary", visible=False)
gen_lojban = gr.Button("generate_lojban", "primary", visible=False)
output_wav = gr.Audio(
label="22kHz audio output",
type="filepath",
editable=False,
autoplay=True,
visible=False
)
# with gr.Column(): # Input column
output_arpabet = gr.HTML(label="ARPAbet")
gen_audio.click(
fn=self.generate,
inputs=[
input_textbox,
voice_radio,
language_radio,
pacing_slider,
anger_slider,
happy_slider,
sad_slider,
surprise_slider,
deepmoji_checkbox
],
outputs=[
output_wav,
output_arpabet,
anger_slider,
happy_slider,
sad_slider,
surprise_slider,
# xVAServer response
gr.Textbox(visible=False)
]
)
gen_lojban.click(
fn=self.lojban,
inputs=[
input_textbox,
voice_radio,
language_radio,
pacing_slider,
anger_slider,
happy_slider,
sad_slider,
surprise_slider,
deepmoji_checkbox
],
outputs=[
output_wav,
output_arpabet,
anger_slider,
happy_slider,
sad_slider,
surprise_slider,
# xVAServer response
gr.Textbox(visible=False)
]
)
return demo
def generate(
self,
input_text: str = "This is what my voice sounds like.",
voice: str = "ccby_nvidia_hifi_6670_M",
lang: str = "en",
pacing: float = 1.0,
anger: float = 0.0,
happy: float = 0.0,
sad: float = 0.0,
surprise: float = 0.0,
deepmoji_checked = 1
):
"""
Convert the text to speech using xVASynth (v3) xVAPitch models. Sensitive to maxed out emotional values
Args:
input_text: string; from which to create the audio
voice: Literal['x_ex04', 'x_ex01', 'ccby_nvidia_hifi_92_F', 'ccby_nvidia_hifi_6671_M', 'x_ex02', 'x_ex03', 'ccby_nvidia_hifi_6670_M', 'ccby_nvidia_hifi_9017_M', 'ccby_nvidia_hifi_6097_M', 'ccby_nvidia_hifi_12787_F', 'ccby_nv_hifi_11614_F', 'ccby_nvidia_hifi_8051_F', 'ccby_nvidia_hifi_11697_F', 'ccby_nvidia_hifi_9136_F']; _M/_F means a male/female voice; x_ex04/x_ex02 are American female voices; x_ex03/x_ex01 are American male voices
lang: Literal['en', 'de', 'es', 'it', 'fr', 'ru', 'tr', 'la', 'ro', 'da', 'vi', 'ha', 'nl', 'zh', 'ar', 'uk', 'hi', 'ko', 'pl', 'sw', 'fi', 'hu', 'pt', 'yo', 'sv', 'el', 'wo', 'jp']; the language of input_text
pacing: float (numeric value between 0.5 and 2.0); Duration; 1.0 is default
anger: float (numeric value between 0 and 1.0); 😠 Anger
happy: float (numeric value between 0 and 1.0); 😃 Happiness
sad: float (numeric value between 0 and 1.0); 😭 Sadness
surprise: float (numeric value between 0 and 1.0); 😮 Surprise
deepmoji_checked: bool; use the DeepMoji model to parse English text and futher amplify the emotional values
Returns:
Tuple of (output_audio_path, arpabet_html, final_anger_ratio, final_happiness_ratio, final_sadness_ratio, final_surprise_ratio, response) where output_audio_path is the filepath of output audio
"""
model = "Pendrokar/xVASynth-TTS"
client = Client("Pendrokar/xVASynth-TTS", hf_token=os.getenv('HF_TOKEN'))
endpoints = client.view_api(all_endpoints=True, print_info=False, return_format='dict')
api_name = '/predict'
fn_index = None
end_parameters = None
text = input_text
end_parameters = _get_param_examples(
endpoints['named_endpoints'][api_name]['parameters']
)
print(end_parameters)
# override some or all default parameters
space_inputs = _override_params(end_parameters, model)
space_inputs[0] = input_text
space_inputs[1] = voice
space_inputs[2] = lang
space_inputs[3] = pacing
space_inputs[6] = anger
space_inputs[7] = happy
space_inputs[8] = sad
space_inputs[9] = surprise
space_inputs[10] = deepmoji_checked
print(space_inputs)
result = client.predict(
*space_inputs,
api_name=api_name
)
return result
def lojban(
self,
input_text: str = "coi rodo",
voice: str = "x_selpahi",
lang: str = "jb",
pacing: float = 1.0,
anger: float = 0.0,
happy: float = 0.0,
sad: float = 0.0,
surprise: float = 0.0,
deepmoji_checked = 1
):
"""
Convert the Lojban text to speech using xVASynth (v2) FastPitch 1.1 models.
Args:
input_text: string; from which to create the audio
voice: Literal['x_selpahi']; the only viable Voice model filenames
lang: Literal['jb']; the language of input_text
pacing: float (numeric value between 0.5 and 2.0); Duration; 1.0 is default
Returns:
Tuple of (output_audio_path, arpabet_html, response) where output_audio_path is the filepath of output audio
"""
model = "Pendrokar/xVASynth-TTS"
client = Client("Pendrokar/xVASynth-TTS", hf_token=os.getenv('HF_TOKEN'))
endpoints = client.view_api(all_endpoints=True, print_info=False, return_format='dict')
api_name = '/predict'
fn_index = None
end_parameters = None
text = input_text
end_parameters = _get_param_examples(
endpoints['named_endpoints'][api_name]['parameters']
)
print(end_parameters)
# override some or all default parameters
space_inputs = _override_params(end_parameters, model)
space_inputs[0] = input_text
space_inputs[1] = voice
space_inputs[2] = 'jbo'
space_inputs[3] = pacing
print(space_inputs)
result = client.predict(
*space_inputs,
api_name=api_name
)
return result
demo = BlocksDemo()
demo.block.launch(show_api=True, show_error=True, mcp_server=True)
|