File size: 11,011 Bytes
e93856a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
001420f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e93856a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6121954
e93856a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6121954
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
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("""
    <div class="wv-header">
      <h1 class="wv-title">WazobiaVoice</h1>
      <p class="wv-sub">
        Nigerian multilingual TTS &amp; voice cloning &nbsp;Β·&nbsp;
        Yoruba &nbsp;Β·&nbsp; Hausa &nbsp;Β·&nbsp; Igbo &nbsp;Β·&nbsp; Pidgin &nbsp;Β·&nbsp; Nigerian English
      </p>
    </div>
    """)

    with gr.Tab("Synthesize"):
        with gr.Row():
            with gr.Column(scale=3):
                text_input = gr.Textbox(
                    label="Text",
                    placeholder="Type text in the language matching your chosen voice...",
                    lines=3,
                )
                voice_dropdown = gr.Dropdown(
                    choices=list(VOICES.keys()),
                    value="IfΓ© (Yoruba, F)",
                    label="Voice",
                )
                with gr.Row():
                    exaggeration_slider = gr.Slider(
                        minimum=0.3, maximum=1.0, value=0.5, step=0.05, label="Exaggeration",
                    )
                    cfg_slider = gr.Slider(
                        minimum=0.2, maximum=1.0, value=0.5, step=0.05, label="CFG Weight",
                    )
                generate_btn = gr.Button("Generate Speech", variant="primary", elem_id="generate-btn")

            with gr.Column(scale=2):
                audio_output = gr.Audio(label="Generated Speech", type="filepath")
                status_text = gr.Textbox(label="Status", interactive=False)

        gr.Examples(
            examples=EXAMPLES,
            inputs=[text_input, voice_dropdown],
            label="Try these",
        )

        generate_btn.click(
            fn=synthesize,
            inputs=[text_input, voice_dropdown, exaggeration_slider, cfg_slider],
            outputs=[audio_output, status_text],
        )

    with gr.Tab("Voice Cloning"):
        gr.Markdown(
            "Upload or record a **5-10 second** reference clip. "
            "WazobiaVoice will speak your chosen language in that voice."
        )
        with gr.Row():
            with gr.Column(scale=3):
                clone_text = gr.Textbox(
                    label="Text to Generate",
                    lines=3,
                )
                clone_language = gr.Dropdown(
                    choices=list(LANG_LABELS.values()),
                    value="Yoruba",
                    label="Language",
                )
                clone_ref_audio = gr.Audio(
                    sources=["microphone", "upload"],
                    label="Reference Audio (5-10 seconds)",
                    type="filepath",
                )
                with gr.Row():
                    clone_exaggeration = gr.Slider(
                        minimum=0.3, maximum=1.0, value=0.5, step=0.05, label="Exaggeration",
                    )
                    clone_cfg = gr.Slider(
                        minimum=0.2, maximum=1.0, value=0.5, step=0.05, label="CFG Weight",
                    )
                clone_btn = gr.Button("Clone & Generate", variant="primary", elem_id="clone-btn")

            with gr.Column(scale=2):
                clone_audio_output = gr.Audio(label="Cloned Speech", type="filepath")
                clone_status = gr.Textbox(label="Status", interactive=False)

        clone_btn.click(
            fn=clone_voice,
            inputs=[clone_text, clone_language, clone_ref_audio, clone_exaggeration, clone_cfg],
            outputs=[clone_audio_output, clone_status],
        )

    gr.HTML("""
    <div class="wv-footer">
      <a href="https://huggingface.co/Axiveri/WazobiaVoice">Model card</a>
      &nbsp;Β·&nbsp;
      <a href="https://github.com/Ememzyvisuals/wazobiavoice-TTS">GitHub</a>
      &nbsp;Β·&nbsp;
      Built by <a href="https://ememzyvisuals.vercel.app">Emmanuel Ariyo</a> Β· Axiveri
    </div>
    """)

demo.launch()