Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,10 +15,10 @@ from f5_tts.infer.utils_infer import (
|
|
15 |
save_spectrogram,
|
16 |
)
|
17 |
|
18 |
-
#
|
19 |
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
20 |
|
21 |
-
#
|
22 |
if hf_token:
|
23 |
login(token=hf_token)
|
24 |
|
@@ -31,6 +31,8 @@ def post_process(text):
|
|
31 |
text = text.replace(" , , ", " , ")
|
32 |
text = " " + text + " "
|
33 |
text = text.replace(" ,, ", " , ")
|
|
|
|
|
34 |
return " ".join(text.split())
|
35 |
|
36 |
# Load models
|
@@ -38,7 +40,7 @@ vocoder = load_vocoder()
|
|
38 |
model = load_model(
|
39 |
DiT,
|
40 |
dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4),
|
41 |
-
ckpt_path=str(cached_path("hf://hynt/F5-TTS-Vietnamese-100h/
|
42 |
vocab_file=str(cached_path("hf://hynt/F5-TTS-Vietnamese-100h/vocab.txt")),
|
43 |
)
|
44 |
|
@@ -46,11 +48,11 @@ model = load_model(
|
|
46 |
def infer_tts(ref_audio_orig: str, gen_text: str, speed: float = 1.0, request: gr.Request = None):
|
47 |
|
48 |
if not ref_audio_orig:
|
49 |
-
raise gr.Error("
|
50 |
if not gen_text.strip():
|
51 |
-
raise gr.Error("
|
52 |
if len(gen_text.split()) > 1000:
|
53 |
-
raise gr.Error("
|
54 |
|
55 |
try:
|
56 |
ref_audio, ref_text = preprocess_ref_audio_text(ref_audio_orig, "")
|
@@ -63,38 +65,39 @@ def infer_tts(ref_audio_orig: str, gen_text: str, speed: float = 1.0, request: g
|
|
63 |
|
64 |
return (final_sample_rate, final_wave), spectrogram_path
|
65 |
except Exception as e:
|
66 |
-
raise gr.Error(f"
|
67 |
|
68 |
# Gradio UI
|
69 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
70 |
gr.Markdown("""
|
71 |
-
# 🎤 F5-TTS:
|
72 |
-
#
|
73 |
-
|
74 |
""")
|
75 |
|
76 |
with gr.Row():
|
77 |
-
ref_audio = gr.Audio(label="🔊
|
78 |
-
gen_text = gr.Textbox(label="📝
|
79 |
|
80 |
-
speed = gr.Slider(0.3, 2.0, value=1.0, step=0.1, label="⚡
|
81 |
-
btn_synthesize = gr.Button("🔥
|
82 |
|
83 |
with gr.Row():
|
84 |
-
output_audio = gr.Audio(label="🎧
|
85 |
output_spectrogram = gr.Image(label="📊 Spectrogram")
|
86 |
|
87 |
model_limitations = gr.Textbox(
|
88 |
-
value="""1.
|
89 |
-
2.
|
90 |
-
3.
|
91 |
-
4.
|
92 |
-
|
93 |
-
|
|
|
94 |
interactive=False
|
95 |
)
|
96 |
|
97 |
btn_synthesize.click(infer_tts, inputs=[ref_audio, gen_text, speed], outputs=[output_audio, output_spectrogram])
|
98 |
|
99 |
-
#
|
100 |
demo.queue().launch()
|
|
|
15 |
save_spectrogram,
|
16 |
)
|
17 |
|
18 |
+
# Retrieve token from secrets
|
19 |
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
20 |
|
21 |
+
# Log in to Hugging Face
|
22 |
if hf_token:
|
23 |
login(token=hf_token)
|
24 |
|
|
|
31 |
text = text.replace(" , , ", " , ")
|
32 |
text = " " + text + " "
|
33 |
text = text.replace(" ,, ", " , ")
|
34 |
+
text = " " + text + " "
|
35 |
+
text = text.replace('"', "")
|
36 |
return " ".join(text.split())
|
37 |
|
38 |
# Load models
|
|
|
40 |
model = load_model(
|
41 |
DiT,
|
42 |
dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4),
|
43 |
+
ckpt_path=str(cached_path("hf://hynt/F5-TTS-Vietnamese-100h/model_470000.pt")),
|
44 |
vocab_file=str(cached_path("hf://hynt/F5-TTS-Vietnamese-100h/vocab.txt")),
|
45 |
)
|
46 |
|
|
|
48 |
def infer_tts(ref_audio_orig: str, gen_text: str, speed: float = 1.0, request: gr.Request = None):
|
49 |
|
50 |
if not ref_audio_orig:
|
51 |
+
raise gr.Error("Please upload a sample audio file.")
|
52 |
if not gen_text.strip():
|
53 |
+
raise gr.Error("Please enter the text content to generate voice.")
|
54 |
if len(gen_text.split()) > 1000:
|
55 |
+
raise gr.Error("Please enter text content with less than 100 words.")
|
56 |
|
57 |
try:
|
58 |
ref_audio, ref_text = preprocess_ref_audio_text(ref_audio_orig, "")
|
|
|
65 |
|
66 |
return (final_sample_rate, final_wave), spectrogram_path
|
67 |
except Exception as e:
|
68 |
+
raise gr.Error(f"Error generating voice: {e}")
|
69 |
|
70 |
# Gradio UI
|
71 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
72 |
gr.Markdown("""
|
73 |
+
# 🎤 F5-TTS: Vietnamese Text-to-Speech Synthesis.
|
74 |
+
# The model was trained for 470,000 steps with approximately 150 hours of data on an RTX 3090 GPU.
|
75 |
+
Enter text and upload a sample voice to generate natural speech.
|
76 |
""")
|
77 |
|
78 |
with gr.Row():
|
79 |
+
ref_audio = gr.Audio(label="🔊 Sample Voice", type="filepath")
|
80 |
+
gen_text = gr.Textbox(label="📝 Text", placeholder="Enter the text to generate voice...", lines=3)
|
81 |
|
82 |
+
speed = gr.Slider(0.3, 2.0, value=1.0, step=0.1, label="⚡ Speed")
|
83 |
+
btn_synthesize = gr.Button("🔥 Generate Voice")
|
84 |
|
85 |
with gr.Row():
|
86 |
+
output_audio = gr.Audio(label="🎧 Generated Audio", type="numpy")
|
87 |
output_spectrogram = gr.Image(label="📊 Spectrogram")
|
88 |
|
89 |
model_limitations = gr.Textbox(
|
90 |
+
value="""1. The model may not perform well with numerical characters, dates, special characters, etc. => A text normalization module is needed.
|
91 |
+
2. The rhythm of some generated audios may be inconsistent or choppy => It is recommended to select clearly pronounced sample audios with minimal pauses for better synthesis quality.
|
92 |
+
3. The reference audio text uses the whisper-large-v3-turbo model, which may not always accurately recognize Vietnamese, resulting in poor voice synthesis quality.
|
93 |
+
4. The current model checkpoint is at around step 470,000, trained with 150 hours of public data => Voice cloning for non-native voices may not be perfectly accurate.
|
94 |
+
5. Inference with overly long paragraphs may produce poor results.""",
|
95 |
+
label="❗ Model Limitations",
|
96 |
+
lines=5,
|
97 |
interactive=False
|
98 |
)
|
99 |
|
100 |
btn_synthesize.click(infer_tts, inputs=[ref_audio, gen_text, speed], outputs=[output_audio, output_spectrogram])
|
101 |
|
102 |
+
# Run Gradio with share=True to get a gradio.live link
|
103 |
demo.queue().launch()
|