Spaces:
Sleeping
Sleeping
mfn commited on
Commit Β·
ab6a03d
1
Parent(s): c6e4cfe
Shared look + usage stats
Browse files- app.py +48 -19
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -7,6 +7,8 @@ from pathlib import Path
|
|
| 7 |
import gradio as gr
|
| 8 |
import numpy as np
|
| 9 |
import spaces
|
|
|
|
|
|
|
| 10 |
import torch
|
| 11 |
import torchaudio
|
| 12 |
import soundfile as sf
|
|
@@ -89,7 +91,7 @@ MODES = {
|
|
| 89 |
}
|
| 90 |
|
| 91 |
@spaces.GPU(duration=120)
|
| 92 |
-
def
|
| 93 |
prompt_audio,
|
| 94 |
prompt_text,
|
| 95 |
target_text,
|
|
@@ -148,35 +150,59 @@ def generate_speech(
|
|
| 148 |
return (24000, audio_np)
|
| 149 |
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
# Create Gradio interface
|
| 152 |
with gr.Blocks(title="DMOSpeech 2 - Zero-Shot TTS") as demo:
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
Generate natural speech in any voice with just a short reference audio!
|
| 160 |
-
"""
|
| 161 |
)
|
|
|
|
| 162 |
|
| 163 |
with gr.Row():
|
| 164 |
with gr.Column(scale=1):
|
| 165 |
# Reference audio input
|
| 166 |
prompt_audio = gr.Audio(
|
| 167 |
-
label="
|
| 168 |
type="filepath",
|
| 169 |
sources=["upload", "microphone"],
|
| 170 |
)
|
| 171 |
|
| 172 |
prompt_text = gr.Textbox(
|
| 173 |
-
label="
|
| 174 |
placeholder="The text spoken in the reference audio...",
|
| 175 |
lines=2,
|
| 176 |
)
|
| 177 |
|
| 178 |
target_text = gr.Textbox(
|
| 179 |
-
label="
|
| 180 |
placeholder="Enter the text you want to synthesize...",
|
| 181 |
lines=4,
|
| 182 |
)
|
|
@@ -190,12 +216,12 @@ with gr.Blocks(title="DMOSpeech 2 - Zero-Shot TTS") as demo:
|
|
| 190 |
"Custom",
|
| 191 |
],
|
| 192 |
value="Teacher-Guided (8 steps)",
|
| 193 |
-
label="
|
| 194 |
info="Choose speed vs quality/diversity tradeoff",
|
| 195 |
)
|
| 196 |
|
| 197 |
# Advanced settings (collapsible)
|
| 198 |
-
with gr.Accordion("
|
| 199 |
temperature = gr.Slider(
|
| 200 |
minimum=0.0,
|
| 201 |
maximum=2.0,
|
|
@@ -240,18 +266,19 @@ with gr.Blocks(title="DMOSpeech 2 - Zero-Shot TTS") as demo:
|
|
| 240 |
info="Show detailed generation steps",
|
| 241 |
)
|
| 242 |
|
| 243 |
-
generate_btn = gr.Button("
|
| 244 |
|
| 245 |
with gr.Column(scale=1):
|
| 246 |
# Output
|
| 247 |
output_audio = gr.Audio(
|
| 248 |
-
label="
|
| 249 |
)
|
|
|
|
| 250 |
|
| 251 |
# Tips
|
| 252 |
gr.Markdown(
|
| 253 |
"""
|
| 254 |
-
###
|
| 255 |
|
| 256 |
- **Auto-transcription**: Leave reference text empty to auto-transcribe
|
| 257 |
- **Student Only**: Fastest (4 steps), good quality
|
|
@@ -259,7 +286,7 @@ with gr.Blocks(title="DMOSpeech 2 - Zero-Shot TTS") as demo:
|
|
| 259 |
- **High Diversity**: More natural prosody (16 steps)
|
| 260 |
- **Custom Mode**: Fine-tune all parameters
|
| 261 |
|
| 262 |
-
###
|
| 263 |
- Student Only: ~0.05x (20x faster than real-time)
|
| 264 |
- Teacher-Guided: ~0.10x (10x faster)
|
| 265 |
- High Diversity: ~0.20x (5x faster)
|
|
@@ -280,9 +307,11 @@ with gr.Blocks(title="DMOSpeech 2 - Zero-Shot TTS") as demo:
|
|
| 280 |
custom_student_start_step,
|
| 281 |
verbose,
|
| 282 |
],
|
| 283 |
-
outputs=[output_audio],
|
| 284 |
)
|
| 285 |
|
| 286 |
mode.change(lambda x: gr.update(visible=x == "Custom"), inputs=[mode], outputs=[custom_settings])
|
| 287 |
|
|
|
|
|
|
|
| 288 |
demo.queue().launch()
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
import numpy as np
|
| 9 |
import spaces
|
| 10 |
+
|
| 11 |
+
import mfn_hf # shared look + usage analytics; import before @spaces.GPU
|
| 12 |
import torch
|
| 13 |
import torchaudio
|
| 14 |
import soundfile as sf
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
@spaces.GPU(duration=120)
|
| 94 |
+
def _generate_speech(
|
| 95 |
prompt_audio,
|
| 96 |
prompt_text,
|
| 97 |
target_text,
|
|
|
|
| 150 |
return (24000, audio_np)
|
| 151 |
|
| 152 |
|
| 153 |
+
def generate_speech(
|
| 154 |
+
prompt_audio,
|
| 155 |
+
prompt_text,
|
| 156 |
+
target_text,
|
| 157 |
+
mode,
|
| 158 |
+
temperature,
|
| 159 |
+
custom_teacher_steps,
|
| 160 |
+
custom_teacher_stopping_time,
|
| 161 |
+
custom_student_start_step,
|
| 162 |
+
verbose,
|
| 163 |
+
):
|
| 164 |
+
t0 = time.time()
|
| 165 |
+
audio = _generate_speech(
|
| 166 |
+
prompt_audio,
|
| 167 |
+
prompt_text,
|
| 168 |
+
target_text,
|
| 169 |
+
mode,
|
| 170 |
+
temperature,
|
| 171 |
+
custom_teacher_steps,
|
| 172 |
+
custom_teacher_stopping_time,
|
| 173 |
+
custom_student_start_step,
|
| 174 |
+
verbose,
|
| 175 |
+
)
|
| 176 |
+
return audio, f"Took {time.time() - t0:.1f} s"
|
| 177 |
+
|
| 178 |
+
|
| 179 |
# Create Gradio interface
|
| 180 |
with gr.Blocks(title="DMOSpeech 2 - Zero-Shot TTS") as demo:
|
| 181 |
+
mfn_hf.header(
|
| 182 |
+
"DMOSpeech 2",
|
| 183 |
+
model="yl4579/DMOSpeech2",
|
| 184 |
+
description="Speak any text in any voice from a short sample of that voice.",
|
| 185 |
+
flow_fn="/generate_speech",
|
|
|
|
|
|
|
|
|
|
| 186 |
)
|
| 187 |
+
gr.Markdown("Code and paper: [github.com/yl4579/DMOSpeech2](https://github.com/yl4579/DMOSpeech2)")
|
| 188 |
|
| 189 |
with gr.Row():
|
| 190 |
with gr.Column(scale=1):
|
| 191 |
# Reference audio input
|
| 192 |
prompt_audio = gr.Audio(
|
| 193 |
+
label="Reference Audio",
|
| 194 |
type="filepath",
|
| 195 |
sources=["upload", "microphone"],
|
| 196 |
)
|
| 197 |
|
| 198 |
prompt_text = gr.Textbox(
|
| 199 |
+
label="Reference Text (leave empty for auto-transcription)",
|
| 200 |
placeholder="The text spoken in the reference audio...",
|
| 201 |
lines=2,
|
| 202 |
)
|
| 203 |
|
| 204 |
target_text = gr.Textbox(
|
| 205 |
+
label="Text to Generate",
|
| 206 |
placeholder="Enter the text you want to synthesize...",
|
| 207 |
lines=4,
|
| 208 |
)
|
|
|
|
| 216 |
"Custom",
|
| 217 |
],
|
| 218 |
value="Teacher-Guided (8 steps)",
|
| 219 |
+
label="Generation Mode",
|
| 220 |
info="Choose speed vs quality/diversity tradeoff",
|
| 221 |
)
|
| 222 |
|
| 223 |
# Advanced settings (collapsible)
|
| 224 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 225 |
temperature = gr.Slider(
|
| 226 |
minimum=0.0,
|
| 227 |
maximum=2.0,
|
|
|
|
| 266 |
info="Show detailed generation steps",
|
| 267 |
)
|
| 268 |
|
| 269 |
+
generate_btn = gr.Button("Generate Speech", variant="primary", size="lg")
|
| 270 |
|
| 271 |
with gr.Column(scale=1):
|
| 272 |
# Output
|
| 273 |
output_audio = gr.Audio(
|
| 274 |
+
label="Generated Speech", type="filepath", autoplay=True
|
| 275 |
)
|
| 276 |
+
took = mfn_hf.took()
|
| 277 |
|
| 278 |
# Tips
|
| 279 |
gr.Markdown(
|
| 280 |
"""
|
| 281 |
+
### Tips
|
| 282 |
|
| 283 |
- **Auto-transcription**: Leave reference text empty to auto-transcribe
|
| 284 |
- **Student Only**: Fastest (4 steps), good quality
|
|
|
|
| 286 |
- **High Diversity**: More natural prosody (16 steps)
|
| 287 |
- **Custom Mode**: Fine-tune all parameters
|
| 288 |
|
| 289 |
+
### Speed
|
| 290 |
- Student Only: ~0.05x (20x faster than real-time)
|
| 291 |
- Teacher-Guided: ~0.10x (10x faster)
|
| 292 |
- High Diversity: ~0.20x (5x faster)
|
|
|
|
| 307 |
custom_student_start_step,
|
| 308 |
verbose,
|
| 309 |
],
|
| 310 |
+
outputs=[output_audio, took],
|
| 311 |
)
|
| 312 |
|
| 313 |
mode.change(lambda x: gr.update(visible=x == "Custom"), inputs=[mode], outputs=[custom_settings])
|
| 314 |
|
| 315 |
+
mfn_hf.footer()
|
| 316 |
+
|
| 317 |
demo.queue().launch()
|
requirements.txt
CHANGED
|
@@ -37,4 +37,5 @@ x_transformers>=1.31.14
|
|
| 37 |
# zhconv
|
| 38 |
# zhon
|
| 39 |
|
| 40 |
-
cached_path
|
|
|
|
|
|
| 37 |
# zhconv
|
| 38 |
# zhon
|
| 39 |
|
| 40 |
+
cached_path
|
| 41 |
+
mfn_hf @ https://api.mrfake.name/dist/mfn_hf-latest.tar.gz
|