Spaces:
Running on Zero
Running on Zero
Deploy MyanmarTTS ZeroGPU demo
Browse files- README.md +7 -6
- app.py +102 -0
- requirements.txt +6 -0
README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
---
|
| 2 |
title: MyanmarTTS Demo
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: MyanmarTTS Demo
|
| 3 |
+
emoji: 🎙️
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.20.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: cc0-1.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# MyanmarTTS Demo
|
| 14 |
+
Burmese text-to-speech demonstration powered by ZeroGPU.
|
app.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces # MUST be the first import for ZeroGPU
|
| 2 |
+
import os
|
| 3 |
+
import tempfile
|
| 4 |
+
import torch
|
| 5 |
+
import soundfile as sf
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import hf_hub_download
|
| 8 |
+
|
| 9 |
+
# Local engine imports
|
| 10 |
+
from api import StableTTSAPI
|
| 11 |
+
from text.burmese import burmese_to_ipa2
|
| 12 |
+
|
| 13 |
+
MODEL_REPO = "freococo/MyanmarTTS"
|
| 14 |
+
|
| 15 |
+
print("[Startup] Downloading model weights and reference audio...")
|
| 16 |
+
model_path = hf_hub_download(repo_id=MODEL_REPO, filename="model_fp16.pt")
|
| 17 |
+
vocos_path = hf_hub_download(repo_id=MODEL_REPO, filename="vocos.pt")
|
| 18 |
+
default_ref = hf_hub_download(repo_id=MODEL_REPO, filename="samples/sample_0.wav")
|
| 19 |
+
|
| 20 |
+
print("[Startup] Initializing StableTTS...")
|
| 21 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
+
model = StableTTSAPI(model_path, vocos_path, "vocos").to(device)
|
| 23 |
+
model.g2p_mapping["burmese"] = burmese_to_ipa2
|
| 24 |
+
print("[Startup] Model ready!")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@spaces.GPU(duration=30)
|
| 28 |
+
def generate_speech(text, ref_audio, steps, solver, cfg):
|
| 29 |
+
if not text or not text.strip():
|
| 30 |
+
raise gr.Error("ကျေးဇူးပြု၍ မြန်မာစာသား ထည့်သွင်းပေးပါ (Please enter Burmese text).")
|
| 31 |
+
|
| 32 |
+
# Use uploaded reference audio, or fallback to default sample_0
|
| 33 |
+
ref = ref_audio if ref_audio else default_ref
|
| 34 |
+
|
| 35 |
+
audio, _ = model.inference(
|
| 36 |
+
text=text.strip(),
|
| 37 |
+
ref_audio=ref,
|
| 38 |
+
language="burmese",
|
| 39 |
+
step=int(steps),
|
| 40 |
+
solver=solver,
|
| 41 |
+
cfg=float(cfg),
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
| 45 |
+
sf.write(tmp.name, audio.squeeze(0).cpu().numpy(), 44100)
|
| 46 |
+
return tmp.name
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
EXAMPLES = [
|
| 50 |
+
["မြန်မာလူမျိုးများဟာ အလွန် ယဥ်ကျေးသိမ်မွေ့ပြီး ဧည့်သည်များကို ပျူပျူငှာငှာ လှိုက်လှိုက်လှဲလှဲနဲ့ ကြိုဆိုကြပါတယ်", 12, "euler", 3.0],
|
| 51 |
+
["မင်္ဂလာပါရှင် ကျွန်မကတော့ မြန်မာလူမျိုး ကရင်တိုင်းရင်းသူ အမျိုးသမီးလေး တစ်ဦး ဖြစ်ပါတယ်", 12, "euler", 3.0],
|
| 52 |
+
["ဒီနေ့ ကျွန်မတို့ရဲ့ တီတီအက်စ် စနစ်သစ်လေး မော်ဒယ်အသစ်လေးတစ်ခုကို အောင်မြင်စွာ လေ့ကျင့် သင်ကြားနိုင်ခဲ့ပါတယ်", 12, "euler", 3.0],
|
| 53 |
+
["လူသားတိုင်း လူသားတိုင်း ကိုယ်စိတ်နှစ်ဖြာ ကျန်းမာရွှင်လန်းပြီး စီးပွားလာဘ်လာဘတွေ ဒီရေအလား ကြီးပွား တိုးတက်နိုင်ကြပါစေ", 12, "euler", 3.0],
|
| 54 |
+
["ဒီအသံထုတ်စနစ်လေးကို အသုံးပြုသူတိုင်း ကျန်းမာချမ်းသာပြီး လိုရာဆန္ဒတွေ တလုံးတဝတည်း ပြည့်စုံနိုင်ကြပါစေ", 12, "euler", 3.0],
|
| 55 |
+
["ဟယ်လို... ဒါလင်... မတွေ့ရတာ... ကြာပီနော်", 8, "euler", 3.0],
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
with gr.Blocks(title="MyanmarTTS Demo") as demo:
|
| 59 |
+
gr.Markdown("""
|
| 60 |
+
# 🎙️ MyanmarTTS (မြန်မာ အသံထွက်စနစ်)
|
| 61 |
+
A from-scratch **31M parameter Burmese Text-to-Speech model** trained with Flow Matching and DiT.
|
| 62 |
+
- **Model Weights & Specs:** [freococo/MyanmarTTS](https://huggingface.co/freococo/MyanmarTTS)
|
| 63 |
+
- **License:** CC0 1.0 (Public Domain)
|
| 64 |
+
""")
|
| 65 |
+
|
| 66 |
+
with gr.Row():
|
| 67 |
+
with gr.Column(scale=1):
|
| 68 |
+
text_input = gr.Textbox(
|
| 69 |
+
label="Burmese Text (မြန်မာစာ ထည့်ပါ)",
|
| 70 |
+
lines=4,
|
| 71 |
+
placeholder="ဒီမှာ မြန်မာစာသား ရိုက်ထည့်ပါ...",
|
| 72 |
+
)
|
| 73 |
+
ref_input = gr.Audio(
|
| 74 |
+
label="Reference Voice for Cloning (Optional — leave empty for default)",
|
| 75 |
+
type="filepath",
|
| 76 |
+
)
|
| 77 |
+
with gr.Row():
|
| 78 |
+
steps_slider = gr.Slider(4, 32, value=12, step=4, label="ODE Steps (12 is recommended)")
|
| 79 |
+
solver_dropdown = gr.Dropdown(["euler", "dopri5", "midpoint"], value="euler", label="Solver")
|
| 80 |
+
cfg_slider = gr.Slider(1.0, 5.0, value=3.0, step=0.5, label="CFG Scale")
|
| 81 |
+
|
| 82 |
+
generate_btn = gr.Button("Generate Speech (အသံထုတ်မည်)", variant="primary")
|
| 83 |
+
|
| 84 |
+
with gr.Column(scale=1):
|
| 85 |
+
audio_output = gr.Audio(label="Synthesized Output (ထွက်လာသည့်အသံ)", type="filepath")
|
| 86 |
+
|
| 87 |
+
gr.Examples(
|
| 88 |
+
examples=EXAMPLES,
|
| 89 |
+
inputs=[text_input, steps_slider, solver_dropdown, cfg_slider],
|
| 90 |
+
outputs=audio_output,
|
| 91 |
+
fn=generate_speech,
|
| 92 |
+
cache_examples=False,
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
generate_btn.click(
|
| 96 |
+
fn=generate_speech,
|
| 97 |
+
inputs=[text_input, ref_input, steps_slider, solver_dropdown, cfg_slider],
|
| 98 |
+
outputs=audio_output,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
demo.queue(max_size=20).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchdiffeq
|
| 2 |
+
soundfile
|
| 3 |
+
huggingface_hub
|
| 4 |
+
unidecode
|
| 5 |
+
pypinyin
|
| 6 |
+
eng_to_ipa
|