hynt commited on
Commit
3b05550
·
1 Parent(s): 4cd445f

Push version 1 F5-TTS-Vietnamese-100h spaces

Browse files
Files changed (3) hide show
  1. app.py +89 -0
  2. packages.txt +5 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from cached_path import cached_path
3
+ import tempfile
4
+ from vinorm import TTSnorm
5
+
6
+ from f5_tts.model import DiT
7
+ from f5_tts.infer.utils_infer import (
8
+ preprocess_ref_audio_text,
9
+ load_vocoder,
10
+ load_model,
11
+ infer_process,
12
+ save_spectrogram,
13
+ )
14
+
15
+ def post_process(text):
16
+ text = " " + text + " "
17
+ text = text.replace(" . . ", " . ")
18
+ text = " " + text + " "
19
+ text = text.replace(" .. ", " . ")
20
+ text = " " + text + " "
21
+ text = text.replace(" , , ", " , ")
22
+ text = " " + text + " "
23
+ text = text.replace(" ,, ", " , ")
24
+ return " ".join(text.split())
25
+
26
+ # Load models
27
+ vocoder = load_vocoder()
28
+ model = load_model(
29
+ DiT,
30
+ dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4),
31
+ ckpt_path=str(cached_path("hf://hynt/F5-TTS-Vietnamese-100h/model_350000.pt")),
32
+ vocab_file=str(cached_path("hf://hynt/F5-TTS-Vietnamese-100h/vocab.txt")),
33
+ )
34
+
35
+ def infer_tts(ref_audio_orig: str, gen_text: str, speed: float = 1.0, request: gr.Request = None):
36
+
37
+ if not ref_audio_orig:
38
+ raise gr.Error("Vui lòng tải lên tệp âm thanh mẫu.")
39
+ if not gen_text.strip():
40
+ raise gr.Error("Vui lòng nhập nội dung cần sinh giọng.")
41
+ if len(gen_text.split()) > 1000:
42
+ raise gr.Error("Vui lòng nhập nội dung cần sinh giọng nhỏ hơn 100 từ.")
43
+
44
+ try:
45
+ ref_audio, ref_text = preprocess_ref_audio_text(ref_audio_orig, "")
46
+ final_wave, final_sample_rate, spectrogram = infer_process(
47
+ ref_audio, ref_text, post_process(TTSnorm(gen_text)), model, vocoder, speed=speed
48
+ )
49
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_spectrogram:
50
+ spectrogram_path = tmp_spectrogram.name
51
+ save_spectrogram(spectrogram, spectrogram_path)
52
+
53
+ return (final_sample_rate, final_wave), spectrogram_path
54
+ except Exception as e:
55
+ raise gr.Error(f"Lỗi khi sinh giọng: {e}")
56
+
57
+ # Gradio UI
58
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
59
+ gr.Markdown("""
60
+ # 🎤 F5-TTS: Tổng hợp giọng nói Tiếng Việt.
61
+ # Mô hình được huấn luyện 350.000 steps với bộ dữ liệu khoảng 100h trên 1 GPU RTX 3090.
62
+ Nhập văn bản và tải lên một mẫu giọng để tạo âm thanh tự nhiên.
63
+ """)
64
+
65
+ with gr.Row():
66
+ ref_audio = gr.Audio(label="🔊 Mẫu giọng", type="filepath")
67
+ gen_text = gr.Textbox(label="📝 Văn bản", placeholder="Nhập nội dung cần sinh giọng...", lines=3)
68
+
69
+ speed = gr.Slider(0.3, 2.0, value=1.0, step=0.1, label="⚡ Tốc độ")
70
+ btn_synthesize = gr.Button("🔥 Sinh giọng")
71
+
72
+ with gr.Row():
73
+ output_audio = gr.Audio(label="🎧 Âm thanh tạo ra", type="numpy")
74
+ output_spectrogram = gr.Image(label="📊 Spectrogram")
75
+
76
+ model_limitations = gr.Textbox(
77
+ value="""1. Mô hình có thể hoạt động không tốt với các ký tự số, ngày tháng, ký tự đặc biệt, ... => cần bổ sung thêm một module text normalization (chuẩn hoá text).
78
+ 2. Nhịp điệu của một số audio có thể chưa được mạch lạc, giật cục.
79
+ 3. Audio reference text sử dụng model whisper-large-v3-turbo nên sẽ có một vài trường hợp không nhận diện chính xác Tiếng Việt, dẫn đến kết quả tổng hợp giọng nói rất tệ.
80
+ 4. Checkpoint của mô hình hiện tại dừng lại ở khoảng step thứ 350.000, được huấn luyện với 100 giờ dữ liệu public.""",
81
+ label="❗ Hạn chế của mô hình",
82
+ lines=4,
83
+ interactive=False
84
+ )
85
+
86
+ btn_synthesize.click(infer_tts, inputs=[ref_audio, gen_text, speed], outputs=[output_audio, output_spectrogram])
87
+
88
+ # Chạy Gradio với share=True để có link gradio.live
89
+ demo.queue().launch()
packages.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ ffmpeg
2
+ sox
3
+ cmake
4
+ gcc
5
+ g++
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ f5-tts
2
+ vinorm