import os import torch import torchaudio as ta import tempfile import gradio as gr import spaces from huggingface_hub import hf_hub_download MODEL_REPO = "Axiveri/WazobiaVoice" from wazobiavoice_tts.mtl_tts import WazobiaVoiceMultilingualTTS print("Loading WazobiaVoice on CPU (moved to GPU per-request via ZeroGPU) ...") model = WazobiaVoiceMultilingualTTS.from_pretrained("cpu") print("Model ready.") # ── Personas ───────────────────────────────────────────────────────────────── # display name -> (language_id, inbuilt_voices reference filename) VOICES = { "Wura (Yoruba, F)": ("yo", "wura.wav"), "Bọlaji (Yoruba, M)": ("yo", "bolaji.wav"), "Elder Deji (Yoruba, M)": ("yo", "elder_deji.wav"), "Ifé (Yoruba, F)": ("yo", "ife.wav"), "Musa (Hausa, M)": ("ha", "musa.wav"), "Hauwa (Hausa, F)": ("ha", "hauwa.wav"), "Emeka (Igbo, M)": ("ig", "emeka.wav"), "Adaeze (Igbo, F)": ("ig", "adaeze.wav"), "Tunde (Pidgin, M)": ("pcm", "tunde.wav"), "Ngozi (Pidgin, F)": ("pcm", "ngozi.wav"), "John (Pidgin, M, teen)": ("pcm", "john.wav"), "James (English, M)": ("en", "james.wav"), "Amara (English, F)": ("en", "amara.wav"), } LANG_LABELS = { "yo": "Yoruba", "ha": "Hausa", "ig": "Igbo", "pcm": "Nigerian Pidgin", "en": "Nigerian English", } REF_CACHE = {} def get_ref_audio(fname): if fname not in REF_CACHE: REF_CACHE[fname] = hf_hub_download( repo_id=MODEL_REPO, filename=f"inbuilt_voices/{fname}" ) return REF_CACHE[fname] EXAMPLES = [ ["Ọrẹ́ mi ti dé láti ìlú ẹ̀kọ́ ní òní, a sì ń sọ̀rọ̀ nípa bí a ṣe ń lọ sí ọjà láti ra ẹ̀wà àti ẹja tó dára fún oúnjẹ̀ alẹ́.", "Wura (Yoruba, F)"], ["Yau na tashi da safe na ci abincin safe sannan na fita zuwa kasuwa don sayen abubuwa na gida kamar gero da yaji da kuma nama mai kyau.", "Musa (Hausa, M)"], ["N'ụtụtụ, m gara ahịa zụta ihe oriri dị ka akwụkwọ nri na azụ̀ ọhụrụ maka nri abalị, ụmụaka na-egwu egwu n'azụ ụlọ.", "Emeka (Igbo, M)"], ["My guy don land from Abuja since morning, we dey gist about how we go reach market buy beans and fresh fish for evening chop.", "Tunde (Pidgin, M)"], ["My friend arrived from Lagos this morning, and we've been chatting about going to the market to buy beans and fresh fish for dinner.", "James (English, M)"], ] @spaces.GPU def synthesize(text, voice_name, exaggeration, cfg_weight): if not text or not text.strip(): return None, "Please enter some text." lang_id, ref_fname = VOICES.get(voice_name, ("en", "james.wav")) try: model.to("cuda") ref_path = get_ref_audio(ref_fname) wav = model.generate( text, language_id=lang_id, audio_prompt_path=ref_path, exaggeration=exaggeration, cfg_weight=cfg_weight, ) tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False) ta.save(tmp.name, wav, model.sr) return tmp.name, f"Generated in {LANG_LABELS[lang_id]} using {voice_name}." except Exception as e: return None, f"Error: {str(e)}" @spaces.GPU def clone_voice(text, language_name, ref_audio, exaggeration, cfg_weight): if not text or not text.strip(): return None, "Please enter some text." if ref_audio is None: return None, "Please upload or record a reference clip (5-10 seconds)." lang_id = {v: k for k, v in LANG_LABELS.items()}[language_name] try: model.to("cuda") wav = model.generate( text, language_id=lang_id, audio_prompt_path=ref_audio, exaggeration=exaggeration, cfg_weight=cfg_weight, ) tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False) ta.save(tmp.name, wav, model.sr) return tmp.name, f"Generated {LANG_LABELS[lang_id]} speech in the cloned voice." except Exception as e: return None, f"Error: {str(e)}" # ── Theme: orange + green + white ─────────────────────────────────────────── ORANGE = gr.themes.Color( c50="#fff7ed", c100="#ffedd5", c200="#fed7aa", c300="#fdba74", c400="#fb923c", c500="#f97316", c600="#ea580c", c700="#c2410c", c800="#9a3412", c900="#7c2d12", c950="#431407", ) GREEN = gr.themes.Color( c50="#f0fdf4", c100="#dcfce7", c200="#bbf7d0", c300="#86efac", c400="#4ade80", c500="#16a34a", c600="#15803d", c700="#166534", c800="#14532d", c900="#0f3d22", c950="#052e16", ) theme = gr.themes.Soft( primary_hue=ORANGE, secondary_hue=GREEN, ).set( button_primary_background_fill="linear-gradient(135deg,#f97316 0%,#ea580c 100%)", button_primary_background_fill_hover="linear-gradient(135deg,#fb923c 0%,#f97316 100%)", button_primary_text_color="#ffffff", slider_color="#f97316", ) CSS = """ html, body { overflow-x: hidden !important; } .gradio-container { max-width: 900px !important; margin: 0 auto !important; padding: 0 1rem !important; overflow-x: hidden !important; box-sizing: border-box !important; } .gradio-container * { box-sizing: border-box !important; } /* The audio waveform (wavesurfer.js canvas) can render at a fixed pixel width wider than a mobile viewport instead of scaling to its container, which pushes the whole page wider than the screen -- only becoming playable once landscape rotation makes the viewport exceed that fixed width. Force it to always respect 100% of its container instead. */ .gradio-container [data-testid="waveform"], .gradio-container [data-testid="waveform"] *, .gradio-container audio { max-width: 100% !important; width: 100% !important; } .gradio-container [data-testid="waveform"] canvas { max-width: 100% !important; } .wv-header { text-align: center; padding: 2rem 0 0.5rem; } .wv-title { font-size: clamp(2.2rem, 6vw, 3.4rem); font-weight: 700; letter-spacing: -0.03em; background: linear-gradient(135deg, #16a34a 0%, #f97316 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; line-height: 1.1; margin: 0 0 0.5rem; } .wv-sub { color: #15803d; font-size: 0.95rem; margin: 0 0 1.5rem; } .wv-footer { text-align: center; padding: 1.5rem 0 2rem; color: #15803d; font-size: 0.82rem; border-top: 1px solid #bbf7d0; margin-top: 1.5rem; } .wv-footer a { color: #c2410c; text-decoration: none; } .wv-footer a:hover { text-decoration: underline; } """ # ── UI ─────────────────────────────────────────────────────────────────────── with gr.Blocks(title="WazobiaVoice Demo", theme=theme, css=CSS) as demo: gr.HTML("""
Nigerian multilingual TTS & voice cloning · Yoruba · Hausa · Igbo · Pidgin · Nigerian English