pnnbao-ump commited on
Commit
a306779
·
1 Parent(s): 70aed5f

preparation for updating gguf version

Browse files
config.yaml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ text_settings:
2
+ max_chars_per_chunk: 256
3
+ max_total_chars_streaming: 3000
4
+
5
+ backbone_configs:
6
+ "SafeTensor (GPU)":
7
+ repo: pnnbao-ump/VieNeu-TTS
8
+ supports_streaming: false
9
+ description: Chất lượng cao nhất, yêu cầu GPU
10
+ "GGUF Q8":
11
+ repo: pnnbao-ump/VieNeu-TTS-q8-gguf
12
+ supports_streaming: true
13
+ description: Cân bằng giữa chất lượng và tốc độ
14
+ "GGUF Q4":
15
+ repo: pnnbao-ump/VieNeu-TTS-q4-gguf
16
+ supports_streaming: true
17
+ description: Nhẹ nhất, phù hợp CPU
18
+
19
+ codec_configs:
20
+ "NeuCodec (Standard)":
21
+ repo: neuphonic/neucodec
22
+ description: Codec chuẩn, tốc độ trung bình
23
+ use_preencoded: false
24
+ "NeuCodec ONNX (Fast CPU)":
25
+ repo: neuphonic/neucodec-onnx-decoder
26
+ description: Tối ưu cho CPU, cần pre-encoded codes
27
+ use_preencoded: true
28
+
29
+ voice_samples:
30
+ "Tuyên (nam miền Bắc)":
31
+ audio: ./sample/Tuyên (nam miền Bắc).wav
32
+ text: ./sample/Tuyên (nam miền Bắc).txt
33
+ codes: ./sample/Tuyên (nam miền Bắc).pt
34
+ "Vĩnh (nam miền Nam)":
35
+ audio: ./sample/Vĩnh (nam miền Nam).wav
36
+ text: ./sample/Vĩnh (nam miền Nam).txt
37
+ codes: ./sample/Vĩnh (nam miền Nam).pt
38
+ "Bình (nam miền Bắc)":
39
+ audio: ./sample/Bình (nam miền Bắc).wav
40
+ text: ./sample/Bình (nam miền Bắc).txt
41
+ codes: ./sample/Bình (nam miền Bắc).pt
42
+ "Nguyên (nam miền Nam)":
43
+ audio: ./sample/Nguyên (nam miền Nam).wav
44
+ text: ./sample/Nguyên (nam miền Nam).txt
45
+ codes: ./sample/Nguyên (nam miền Nam).pt
46
+ "Sơn (nam miền Nam)":
47
+ audio: ./sample/Sơn (nam miền Nam).wav
48
+ text: ./sample/Sơn (nam miền Nam).txt
49
+ codes: ./sample/Sơn (nam miền Nam).pt
50
+ "Đoan (nữ miền Nam)":
51
+ audio: ./sample/Đoan (nữ miền Nam).wav
52
+ text: ./sample/Đoan (nữ miền Nam).txt
53
+ codes: ./sample/Đoan (nữ miền Nam).pt
54
+ "Ngọc (nữ miền Bắc)":
55
+ audio: ./sample/Ngọc (nữ miền Bắc).wav
56
+ text: ./sample/Ngọc (nữ miền Bắc).txt
57
+ codes: ./sample/Ngọc (nữ miền Bắc).pt
58
+ "Ly (nữ miền Bắc)":
59
+ audio: ./sample/Ly (nữ miền Bắc).wav
60
+ text: ./sample/Ly (nữ miền Bắc).txt
61
+ codes: ./sample/Ly (nữ miền Bắc).pt
62
+ "Dung (nữ miền Nam)":
63
+ audio: ./sample/Dung (nữ miền Nam).wav
64
+ text: ./sample/Dung (nữ miền Nam).txt
65
+ codes: ./sample/Dung (nữ miền Nam).pt
examples/sample_long_text.txt CHANGED
@@ -1 +1,4 @@
1
- Trong kỷ nguyên số, việc tiếp cận thông tin đã trở nên dễ dàng hơn bao giờ hết. Chúng ta có thể đọc báo trực tuyến, xem video và tham gia các lớp học từ xa chỉ với một chiếc điện thoại thông minh. Tuy nhiên, khối lượng nội dung khổng lồ này đôi khi khiến người học cảm thấy choáng ngợp. Một chiến lược hiệu quả là chia nhỏ tài liệu thành các đoạn ngắn, mỗi đoạn tập trung vào một ý chính, nhằm giúp não bộ xử lý thông tin tốt hơn. Khi áp dụng kỹ thuật này cho việc luyện nghe tiếng Việt, người học không chỉ cải thiện kỹ năng ngôn ngữ mà còn rèn luyện được khả năng tập trung và ghi nhớ. Ngoài ra, việc nghe lại giọng của chính mình qua các công cụ tổng hợp tiếng nói cũng giúp phát hiện lỗi phát âm và chỉnh sửa kịp thời.
 
 
 
 
1
+ Buổi sáng hôm ấy, ánh nắng vàng óng từ từ lan tỏa qua những tán cây xanh mướt, tạo nên những vệt sáng lung linh trên mặt đất. Tiếng chim hót véo von vang lên khắp khu rừng, hòa quyện cùng tiếng suối chảy róc rách từ phía xa. Không khí trong lành, mát mẻ khiến người ta cảm thấy sảng khoái và tràn đầy năng lượng.
2
+ Tôi bước chậm rãi trên con đường mòn quanh co, ngắm nhìn những bông hoa dại đủ màu sắc nở rộ bên vệ đường. Có những bông hoa màu tím nhạt, có những bông màu vàng rực rỡ, và cả những bông hoa trắng tinh khôi như những vì sao nhỏ. Gió nhẹ thổi qua, mang theo hương thơm ngào ngạt của hoa lá, khiến lòng người ta thư thái và bình yên đến lạ.
3
+ Đi một đoạn nữa, tôi đến một cánh đồng lúa chín vàng trải dài bất tận. Những đợt sóng lúa nhấp nhô theo gió, tạo nên một bức tranh thiên nhiên tuyệt đẹp. Xa xa, những người nông dân đang miệt mài gặt lúa, tiếng cười nói vui vẻ của họ vang lên, hòa cùng tiếng ve kêu râm ran. Đó là bức tranh của một mùa màng bội thu, của sự cần cù và đoàn kết.
4
+ Cuộc sống thật đơn giản nhưng đầy ý nghĩa khi ta biết trân trọng những khoảnh khắc nhỏ bé như thế này. Mỗi ngày trôi qua là một món quà, một cơ hội để ta được tận hưởng vẻ đẹp của thiên nhiên và sự ấm áp của tình người.
gradio_app.py CHANGED
@@ -5,47 +5,126 @@ import torch
5
  from vieneu_tts import VieNeuTTS
6
  import os
7
  import time
 
 
 
 
 
 
 
8
 
9
  print("⏳ Đang khởi động VieNeu-TTS...")
10
 
11
- # --- 1. SETUP MODEL ---
12
- print("📦 Đang tải model...")
13
- device = "cuda" if torch.cuda.is_available() else "cpu"
14
- print(f"🖥️ Sử dụng thiết bị: {device.upper()}")
15
-
16
  try:
17
- tts = VieNeuTTS(
18
- backbone_repo="pnnbao-ump/VieNeu-TTS",
19
- backbone_device=device,
20
- codec_repo="neuphonic/neucodec",
21
- codec_device=device
22
- )
23
- print("✅ Model đã tải xong!")
24
  except Exception as e:
25
- print(f"⚠️ Không thể tải model (Chế độ UI Demo): {e}")
26
- class MockTTS:
27
- def encode_reference(self, path): return None
28
- def infer(self, text, ref, ref_text):
29
- import numpy as np
30
- # Giả lập độ trễ để test tính năng đo thời gian
31
- time.sleep(1.5)
32
- return np.random.uniform(-0.5, 0.5, 24000*3)
33
- tts = MockTTS()
34
-
35
- # --- 2. DATA ---
36
- VOICE_SAMPLES = {
37
- "Tuyên (nam miền Bắc)": {"audio": "./sample/Tuyên (nam miền Bắc).wav", "text": "./sample/Tuyên (nam miền Bắc).txt"},
38
- "Vĩnh (nam miền Nam)": {"audio": "./sample/Vĩnh (nam miền Nam).wav", "text": "./sample/Vĩnh (nam miền Nam).txt"},
39
- "Bình (nam miền Bắc)": {"audio": "./sample/Bình (nam miền Bắc).wav", "text": "./sample/Bình (nam miền Bắc).txt"},
40
- "Nguyên (nam miền Nam)": {"audio": "./sample/Nguyên (nam miền Nam).wav", "text": "./sample/Nguyên (nam miền Nam).txt"},
41
- "Sơn (nam miền Nam)": {"audio": "./sample/Sơn (nam miền Nam).wav", "text": "./sample/Sơn (nam miền Nam).txt"},
42
- "Đoan (nữ miền Nam)": {"audio": "./sample/Đoan (nữ miền Nam).wav", "text": "./sample/Đoan (nữ miền Nam).txt"},
43
- "Ngọc (nữ miền Bắc)": {"audio": "./sample/Ngọc (nữ miền Bắc).wav", "text": "./sample/Ngọc (nữ miền Bắc).txt"},
44
- "Ly (nữ miền Bắc)": {"audio": "./sample/Ly (nữ miền Bắc).wav", "text": "./sample/Ly (nữ miền Bắc).txt"},
45
- "Dung (nữ miền Nam)": {"audio": "./sample/Dung (nữ miền Nam).wav", "text": "./sample/Dung (nữ miền Nam).txt"}
46
- }
47
-
48
- # --- 3. HELPER FUNCTIONS ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  def load_reference_info(voice_choice):
50
  if voice_choice in VOICE_SAMPLES:
51
  audio_path = VOICE_SAMPLES[voice_choice]["audio"]
@@ -61,58 +140,211 @@ def load_reference_info(voice_choice):
61
  return None, f"❌ Lỗi: {str(e)}"
62
  return None, ""
63
 
64
- def synthesize_speech(text, voice_choice, custom_audio, custom_text, mode_tab):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  try:
66
- if not text or text.strip() == "":
67
- return None, "⚠️ Vui lòng nhập văn bản cần tổng hợp!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- # --- LOGIC CHECK LIMIT 250 ---
70
- if len(text) > 250:
71
- return None, f"❌ Văn bản quá dài ({len(text)}/250 ký tự)! Vui lòng cắt ngắn lại để đảm bảo chất lượng."
72
-
73
- # Logic chọn Reference
74
- if mode_tab == "custom_mode":
75
- if custom_audio is None or not custom_text:
76
- return None, "⚠️ Vui lòng tải lên Audio và nhập nội dung Audio đó."
77
- ref_audio_path = custom_audio
78
- ref_text_raw = custom_text
79
- print("🎨 Mode: Custom Voice")
80
- else: # Preset
81
- if voice_choice not in VOICE_SAMPLES:
82
- return None, "⚠️ Vui lòng chọn một giọng mẫu."
83
- ref_audio_path = VOICE_SAMPLES[voice_choice]["audio"]
84
- ref_text_path = VOICE_SAMPLES[voice_choice]["text"]
85
 
86
- if not os.path.exists(ref_audio_path):
87
- return None, f"❌ Không tìm thấy file audio: {ref_audio_path}"
88
-
89
- with open(ref_text_path, "r", encoding="utf-8") as f:
90
- ref_text_raw = f.read()
91
- print(f"🎤 Mode: Preset Voice ({voice_choice})")
92
-
93
- # Inference & Đo thời gian
94
- print(f"📝 Text: {text[:50]}...")
 
 
 
 
 
 
 
 
95
 
96
- start_time = time.time() # <--- Bắt đầu bấm giờ
 
 
97
 
98
- ref_codes = tts.encode_reference(ref_audio_path)
99
- wav = tts.infer(text, ref_codes, ref_text_raw)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
- end_time = time.time() # <--- Kết thúc bấm giờ
102
- process_time = end_time - start_time # <--- Tính thời gian xử lý
 
 
 
 
 
 
 
 
 
 
103
 
104
- # Save
105
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
106
- sf.write(tmp_file.name, wav, 24000)
107
- output_path = tmp_file.name
 
108
 
109
- # <--- Cập nhật thông báo kết quả
110
- return output_path, f"✅ Thành công! (Mất {process_time:.2f} giây để tạo)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- except Exception as e:
113
- import traceback
114
- traceback.print_exc()
115
- return None, f"❌ Lỗi hệ thống: {str(e)}"
 
 
116
 
117
  # --- 4. UI SETUP ---
118
  theme = gr.themes.Ocean(
@@ -123,192 +355,89 @@ theme = gr.themes.Ocean(
123
  ).set(
124
  button_primary_background_fill="linear-gradient(90deg, #6366f1 0%, #0ea5e9 100%)",
125
  button_primary_background_fill_hover="linear-gradient(90deg, #4f46e5 0%, #0284c7 100%)",
126
- block_shadow="0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
127
  )
128
 
129
- # <--- CSS ĐÃ SỬA (Background xanh đen + Chữ sáng)
130
  css = """
131
- .container { max-width: 1200px; margin: auto; }
132
- .header-box {
133
- text-align: center;
134
- margin-bottom: 25px;
135
- padding: 25px;
136
- background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); /* Xanh đen (Slate 900 -> 800) */
137
- border-radius: 12px;
138
- border: 1px solid #334155;
139
- box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
140
- }
141
- .header-title {
142
- font-size: 2.5rem;
143
- font-weight: 800;
144
- color: white; /* Chữ trắng */
145
- background: -webkit-linear-gradient(45deg, #60A5FA, #22D3EE); /* Gradient xanh sáng cho chữ nổi bật */
146
- -webkit-background-clip: text;
147
- -webkit-text-fill-color: transparent;
148
- margin-bottom: 10px;
149
- }
150
- .header-desc {
151
- font-size: 1.1rem;
152
- color: #cbd5e1; /* Màu xám sáng (Slate-300) */
153
- margin-bottom: 15px;
154
- }
155
- .link-group a {
156
- text-decoration: none;
157
- margin: 0 10px;
158
- font-weight: 600;
159
- color: #94a3b8; /* Màu link sáng hơn chút */
160
- transition: color 0.2s;
161
- }
162
- .link-group a:hover { color: #38bdf8; text-shadow: 0 0 5px rgba(56, 189, 248, 0.5); }
163
-
164
  .status-box { font-weight: bold; text-align: center; border: none; background: transparent; }
165
- .warning-note {
166
- background-color: #fff7ed;
167
- border-left: 4px solid #f97316;
168
- padding: 12px;
169
- color: #9a3412;
170
- font-size: 0.9rem;
171
- border-radius: 4px;
172
- margin-top: 10px;
173
- margin-bottom: 10px;
174
- }
175
  """
176
 
177
  EXAMPLES_LIST = [
178
- # Nam Miền Nam
179
- ["Về miền Tây không chỉ để ngắm nhìn sông nước hữu tình, mà còn để cảm nhận tấm chân tình của người dân nơi đây. C��ng ngồi xuồng ba lá len lỏi qua rặng dừa nước, nghe câu vọng cổ ngọt ngào thì còn gì bằng.", "Vĩnh (nam miền Nam)"],
180
-
181
- # Nam Miền Bắc
182
- ["Hà Nội những ngày vào thu mang một vẻ đẹp trầm mặc và cổ kính đến lạ thường. Đi dạo quanh Hồ Gươm vào sáng sớm, hít hà mùi hoa sữa nồng nàn và thưởng thức chút cốm làng Vòng là trải nghiệm khó quên.", "Bình (nam miền Bắc)"],
183
-
184
- # Nam Miền Bắc
185
- ["Sự bùng nổ của trí tuệ nhân tạo đang định hình lại cách chúng ta làm việc và sinh sống. Từ xe tự lái đến trợ lý ảo thông minh, công nghệ đang dần xóa nhòa ranh giới giữa thực tại và những bộ phim viễn tưởng.", "Tuyên (nam miền Bắc)"],
186
-
187
- # Nam Miền Nam
188
- ["Sài Gòn hối hả là thế, nhưng chỉ cần tấp vào một quán cà phê ven đường, gọi ly bạc xỉu đá và ngắm nhìn dòng người qua lại, bạn sẽ thấy thành phố này cũng có những khoảng lặng thật bình yên và đáng yêu.", "Nguyên (nam miền Nam)"],
189
-
190
- # Nam Miền Nam
191
- ["Để đảm bảo tiến độ dự án quan trọng này, chúng ta cần tập trung tối đa nguồn lực và phối hợp chặt chẽ giữa các phòng ban. Mọi khó khăn phát sinh cần được báo cáo ngay lập tức để ban lãnh đạo xử lý kịp thời.", "Sơn (nam miền Nam)"],
192
-
193
- # Nữ Miền Nam
194
- ["Ngày xửa ngày xưa, ở một ngôi làng nọ có cô Tấm xinh đẹp, nết na nhưng sớm mồ côi mẹ. Dù bị mẹ kế và Cám hãm hại đủ đường, Tấm vẫn giữ được tấm lòng lương thiện và cuối cùng tìm được hạnh phúc xứng đáng.", "Đoan (nữ miền Nam)"],
195
-
196
- # Nữ Miền Bắc
197
- ["Dạ em chào anh chị, hiện tại bên em đang có chương trình ưu đãi đặc biệt cho căn hộ hướng sông này. Với thiết kế hiện đại và không gian xanh mát, đây chắc chắn là tổ ấm lý tưởng mà gia đình mình đang tìm kiếm.", "Ly (nữ miền Bắc)"],
198
-
199
- # Nữ Miền Bắc
200
- ["Dưới cơn mưa phùn lất phất của những ngày cuối đông, em khẽ nép vào vai anh, cảm nhận hơi ấm lan tỏa. Những khoảnh khắc bình dị như thế này khiến em nhận ra rằng, hạnh phúc đôi khi chỉ đơn giản là được ở bên nhau.", "Ngọc (nữ miền Bắc)"],
201
  ]
202
 
203
- with gr.Blocks(theme=theme, css=css, title="VieNeu-TTS Studio") as demo:
204
 
205
  with gr.Column(elem_classes="container"):
206
- # Header - Cập nhật class cho HTML
207
- gr.HTML("""
208
- <div class="header-box">
209
- <div class="header-title">🎙️ VieNeu-TTS Studio</div>
210
- <div class="header-desc">
211
- Phiên bản: VieNeu-TTS-1000h (model mới nhất, train trên 1000 giờ dữ liệu)
212
- </div>
213
- <div class="link-group">
214
- <a href="https://huggingface.co/pnnbao-ump/VieNeu-TTS" target="_blank">🤗 Model Card</a> •
215
- <a href="https://huggingface.co/datasets/pnnbao-ump/VieNeu-TTS-1000h" target="_blank">📖 Dataset 1000h</a> •
216
- <a href="https://github.com/pnnbao97/VieNeu-TTS" target="_blank">🦜 GitHub</a>
217
- </div>
218
- </div>
219
- """)
220
-
221
- with gr.Row(elem_classes="container", equal_height=False):
222
 
223
- # --- LEFT: INPUT ---
224
- with gr.Column(scale=3, variant="panel"):
225
- gr.Markdown("### 📝 Văn bản đầu vào")
226
- text_input = gr.Textbox(
227
- label="Nhập văn bản",
228
- placeholder="Nhập nội dung tiếng Việt cần chuyển thành giọng nói...",
229
- lines=4,
230
- value="Sự bùng nổ của trí tuệ nhân tạo đang định hình lại cách chúng ta làm việc và sinh sống. Từ xe tự lái đến trợ lý ảo thông minh, công nghệ đang dần xóa nhòa ranh giới giữa thực tại và những bộ phim viễn tưởng.",
231
- show_label=False
232
- )
233
 
234
- # Counter + Warning
235
  with gr.Row():
236
- char_count = gr.HTML("<div style='text-align: right; color: #64748B; font-size: 0.8rem;'>0 / 250 ký tự</div>")
 
 
 
 
 
 
 
 
 
 
237
 
238
- gr.Markdown("### 🗣️ Chọn giọng đọc")
239
  with gr.Tabs() as tabs:
240
- with gr.TabItem("👤 Giọng có sẵn (Preset)", id="preset_mode"):
241
- voice_select = gr.Dropdown(
242
- choices=list(VOICE_SAMPLES.keys()),
243
- value="Tuyên (nam miền Bắc)",
244
- label="Danh sách giọng",
245
- interactive=True
246
- )
247
- with gr.Accordion("Thông tin giọng mẫu", open=False):
248
- ref_audio_preview = gr.Audio(label="Audio mẫu", interactive=False, type="filepath")
249
- ref_text_preview = gr.Markdown("...")
250
-
251
- with gr.TabItem("🎙️ Giọng tùy chỉnh (Custom)", id="custom_mode"):
252
- gr.Markdown("Tải lên giọng của bạn (Zero-shot Cloning)")
253
- custom_audio = gr.Audio(label="File ghi âm (.wav)", type="filepath")
254
- custom_text = gr.Textbox(label="Nội dung ghi âm", placeholder="Nhập chính xác lời thoại...")
255
 
 
 
 
 
 
256
  current_mode = gr.Textbox(visible=False, value="preset_mode")
257
- btn_generate = gr.Button("Tổng hợp giọng nói", variant="primary", size="lg")
258
 
259
- # --- RIGHT: OUTPUT ---
260
  with gr.Column(scale=2):
261
- gr.Markdown("### 🎧 Kết quả")
262
- with gr.Group():
263
- audio_output = gr.Audio(label="Audio đầu ra", type="filepath", show_download_button=True, autoplay=True)
264
- status_output = gr.Textbox(label="Trạng thái", show_label=False, elem_classes="status-box", placeholder="Sẵn sàng...")
265
-
266
- # --- EXAMPLES ---
267
- with gr.Row(elem_classes="container"):
268
- with gr.Column():
269
- gr.Markdown("### 📚 Ví dụ mẫu")
270
- gr.Examples(examples=EXAMPLES_LIST, inputs=[text_input, voice_select], label="Thử nghiệm nhanh")
271
-
272
- # --- LOGIC ---
273
- def update_count(text):
274
- l = len(text)
275
- if l > 250:
276
- color = "#dc2626" # Red
277
- msg = f"⚠️ <b>{l} / 250</b> - Quá giới hạn!"
278
- elif l > 200:
279
- color = "#ea580c" # Orange
280
- msg = f"{l} / 250"
281
- else:
282
- color = "#64748B" # Gray
283
- msg = f"{l} / 250 ký tự"
284
- return f"<div style='text-align: right; color: {color}; font-size: 0.8rem; font-weight: bold'>{msg}</div>"
285
-
286
- text_input.change(update_count, text_input, char_count)
287
 
288
- def update_ref_preview(voice):
289
- audio, text = load_reference_info(voice)
290
- return audio, f"> *\"{text}\"*"
291
 
292
- voice_select.change(update_ref_preview, voice_select, [ref_audio_preview, ref_text_preview])
293
- demo.load(update_ref_preview, voice_select, [ref_audio_preview, ref_text_preview])
 
 
294
 
295
- # Tab handling - FIXED WITH *ARGS
296
- tab_preset = tabs.children[0]
297
- tab_custom = tabs.children[1]
298
-
299
- # Dùng *args để nhận bất kỳ số lượng tham số nào (0 hoặc 1), tránh lỗi Warning
300
- tab_preset.select(fn=lambda *args: "preset_mode", inputs=None, outputs=current_mode)
301
- tab_custom.select(fn=lambda *args: "custom_mode", inputs=None, outputs=current_mode)
302
 
303
  btn_generate.click(
304
  fn=synthesize_speech,
305
- inputs=[text_input, voice_select, custom_audio, custom_text, current_mode],
306
  outputs=[audio_output, status_output]
307
  )
308
 
309
  if __name__ == "__main__":
310
- demo.queue().launch(
311
- server_name="127.0.0.1",
312
- server_port=7860,
313
- share=False
314
- )
 
5
  from vieneu_tts import VieNeuTTS
6
  import os
7
  import time
8
+ import numpy as np
9
+ import re
10
+ from typing import Generator
11
+ import queue
12
+ import threading
13
+ import yaml
14
+ from utils.core_utils import split_text_into_chunks
15
 
16
  print("⏳ Đang khởi động VieNeu-TTS...")
17
 
18
+ # --- CONSTANTS & CONFIG ---
19
+ CONFIG_PATH = os.path.join(os.path.dirname(__file__), "config.yaml")
 
 
 
20
  try:
21
+ with open(CONFIG_PATH, "r", encoding="utf-8") as f:
22
+ _config = yaml.safe_load(f) or {}
 
 
 
 
 
23
  except Exception as e:
24
+ raise RuntimeError(f"Không thể đọc config.yaml: {e}")
25
+
26
+ BACKBONE_CONFIGS = _config.get("backbone_configs", {})
27
+ CODEC_CONFIGS = _config.get("codec_configs", {})
28
+ VOICE_SAMPLES = _config.get("voice_samples", {})
29
+ _text_settings = _config.get("text_settings", {})
30
+ MAX_CHARS_PER_CHUNK = _text_settings.get("max_chars_per_chunk", 256)
31
+ MAX_TOTAL_CHARS_STREAMING = _text_settings.get("max_total_chars_streaming", 3000)
32
+
33
+ if not BACKBONE_CONFIGS or not CODEC_CONFIGS:
34
+ raise ValueError("config.yaml thiếu backbone_configs hoặc codec_configs")
35
+ if not VOICE_SAMPLES:
36
+ raise ValueError("config.yaml thiếu voice_samples")
37
+
38
+ # --- 1. MODEL CONFIGURATION ---
39
+
40
+ # Global model instance
41
+ tts = None
42
+ current_backbone = None
43
+ current_codec = None
44
+
45
+ def load_model(backbone_choice, codec_choice, device_choice):
46
+ """Load model with specified configuration"""
47
+ global tts, current_backbone, current_codec
48
+
49
+ try:
50
+ backbone_config = BACKBONE_CONFIGS[backbone_choice]
51
+ codec_config = CODEC_CONFIGS[codec_choice]
52
+
53
+ # Determine devices
54
+ if device_choice == "Auto":
55
+ if "GGUF" in backbone_choice:
56
+ backbone_device = "gpu" if torch.cuda.is_available() else "cpu"
57
+ else:
58
+ backbone_device = "cuda" if torch.cuda.is_available() else "cpu"
59
+
60
+ if "ONNX" in codec_choice:
61
+ codec_device = "cpu"
62
+ else:
63
+ codec_device = "cuda" if torch.cuda.is_available() else "cpu"
64
+ else:
65
+ backbone_device = device_choice.lower()
66
+ codec_device = device_choice.lower()
67
+
68
+ if "ONNX" in codec_choice:
69
+ codec_device = "cpu"
70
+
71
+ if "GGUF" in backbone_choice and backbone_device == "cuda":
72
+ backbone_device = "gpu"
73
+
74
+ print(f"📦 Đang tải model...")
75
+ print(f" Backbone: {backbone_config['repo']} on {backbone_device}")
76
+ print(f" Codec: {codec_config['repo']} on {codec_device}")
77
+
78
+ tts = VieNeuTTS(
79
+ backbone_repo=backbone_config["repo"],
80
+ backbone_device=backbone_device,
81
+ codec_repo=codec_config["repo"],
82
+ codec_device=codec_device
83
+ )
84
+
85
+ current_backbone = backbone_choice
86
+ current_codec = codec_choice
87
+
88
+ streaming_support = "✅ Có" if backbone_config['supports_streaming'] else "❌ Không"
89
+ preencoded_note = "\n⚠️ Codec này cần sử dụng pre-encoded codes (.pt files)" if codec_config['use_preencoded'] else ""
90
+
91
+ return (
92
+ f"✅ Model đã tải thành công!\n\n"
93
+ f"🦜 Model Device: {backbone_device.upper()}\n\n"
94
+ f"🎵 Codec Device: {codec_device.upper()}{preencoded_note}"
95
+ )
96
+
97
+ except Exception as e:
98
+ import traceback
99
+ traceback.print_exc()
100
+ return f"❌ Lỗi khi tải model: {str(e)}"
101
+
102
+ # --- 2. DATA & HELPERS ---
103
+
104
+ GGUF_ALLOWED_VOICES = [
105
+ "Vĩnh (nam miền Nam)",
106
+ "Bình (nam miền Bắc)",
107
+ "Ngọc (nữ miền Bắc)",
108
+ "Dung (nữ miền Nam)",
109
+ ]
110
+
111
+
112
+ def get_voice_options(backbone_choice: str):
113
+ """Filter voice options: GGUF only shows the 4 allowed voices."""
114
+ if "GGUF" in backbone_choice:
115
+ return [v for v in GGUF_ALLOWED_VOICES if v in VOICE_SAMPLES]
116
+ return list(VOICE_SAMPLES.keys())
117
+
118
+
119
+ def update_voice_dropdown(backbone_choice: str, current_voice: str):
120
+ options = get_voice_options(backbone_choice)
121
+ new_value = current_voice if current_voice in options else (options[0] if options else None)
122
+ # gr.update is available across Gradio versions to update component props
123
+ return gr.update(choices=options, value=new_value)
124
+
125
+
126
+ # --- 3. CORE LOGIC FUNCTIONS ---
127
+
128
  def load_reference_info(voice_choice):
129
  if voice_choice in VOICE_SAMPLES:
130
  audio_path = VOICE_SAMPLES[voice_choice]["audio"]
 
140
  return None, f"❌ Lỗi: {str(e)}"
141
  return None, ""
142
 
143
+ def synthesize_speech(text, voice_choice, custom_audio, custom_text, mode_tab, generation_mode):
144
+ """Cải tiến streaming với pre-buffering và crossfade mượt hơn"""
145
+ global tts, current_backbone, current_codec
146
+
147
+ # === VALIDATION (giữ nguyên) ===
148
+ if tts is None:
149
+ yield None, "⚠️ Vui lòng tải model trước!"
150
+ return
151
+ if not text or text.strip() == "":
152
+ yield None, "⚠️ Vui lòng nhập văn bản!"
153
+ return
154
+
155
+ raw_text = text.strip()
156
+ codec_config = CODEC_CONFIGS[current_codec]
157
+ use_preencoded = codec_config['use_preencoded']
158
+
159
+ # Setup Reference (giữ nguyên logic cũ)
160
+ if mode_tab == "custom_mode":
161
+ if custom_audio is None or not custom_text:
162
+ yield None, "⚠️ Thiếu Audio hoặc Text mẫu custom."
163
+ return
164
+ ref_audio_path = custom_audio
165
+ ref_text_raw = custom_text
166
+ ref_codes_path = None
167
+ else:
168
+ if voice_choice not in VOICE_SAMPLES:
169
+ yield None, "⚠️ Vui lòng chọn giọng mẫu."
170
+ return
171
+ ref_audio_path = VOICE_SAMPLES[voice_choice]["audio"]
172
+ ref_text_path = VOICE_SAMPLES[voice_choice]["text"]
173
+ ref_codes_path = VOICE_SAMPLES[voice_choice]["codes"]
174
+ if not os.path.exists(ref_audio_path):
175
+ yield None, "❌ Không tìm thấy file audio mẫu."
176
+ return
177
+ with open(ref_text_path, "r", encoding="utf-8") as f:
178
+ ref_text_raw = f.read()
179
+
180
+ yield None, "📄 Đang xử lý Reference..."
181
+
182
+ # Encode reference
183
  try:
184
+ if use_preencoded and ref_codes_path and os.path.exists(ref_codes_path):
185
+ ref_codes = torch.load(ref_codes_path, map_location="cpu")
186
+ else:
187
+ ref_codes = tts.encode_reference(ref_audio_path)
188
+ if isinstance(ref_codes, torch.Tensor):
189
+ ref_codes = ref_codes.cpu().numpy()
190
+ except Exception as e:
191
+ yield None, f"❌ Lỗi xử lý reference: {e}"
192
+ return
193
+
194
+ text_chunks = split_text_into_chunks(raw_text, max_chars=MAX_CHARS_PER_CHUNK)
195
+ total_chunks = len(text_chunks)
196
+
197
+ # === STANDARD MODE ===
198
+ if generation_mode == "Standard (Một lần)":
199
+ yield None, f"🚀 Bắt đầu tổng hợp chế độ Standard ({total_chunks} đoạn)..."
200
+ all_audio_segments = []
201
+ sr = 24000
202
+ silence_pad = np.zeros(int(sr * 0.15), dtype=np.float32)
203
+ start_time = time.time()
204
 
205
+ try:
206
+ for i, chunk in enumerate(text_chunks):
207
+ yield None, f"⏳ Đang xử lý đoạn {i+1}/{total_chunks}..."
208
+ chunk_wav = tts.infer(chunk, ref_codes, ref_text_raw)
209
+ if chunk_wav is not None and len(chunk_wav) > 0:
210
+ all_audio_segments.append(chunk_wav)
211
+ if i < total_chunks - 1:
212
+ all_audio_segments.append(silence_pad)
213
+
214
+ if not all_audio_segments:
215
+ yield None, "❌ Không sinh được audio nào."
216
+ return
217
+
218
+ yield None, "💾 Đang ghép file và lưu..."
219
+ final_wav = np.concatenate(all_audio_segments)
 
220
 
221
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
222
+ sf.write(tmp.name, final_wav, sr)
223
+ output_path = tmp.name
224
+
225
+ process_time = time.time() - start_time
226
+ yield output_path, f"✅ Hoàn tất! (Tổng thời gian: {process_time:.2f}s)"
227
+
228
+ except Exception as e:
229
+ import traceback
230
+ traceback.print_exc()
231
+ yield None, f"❌ Lỗi Standard Mode: {str(e)}"
232
+ return
233
+
234
+ # === STREAMING MODE ===
235
+ else:
236
+ sr = 24000
237
+ crossfade_samples = int(sr * 0.03)
238
 
239
+ # CẢI TIẾN 1: Tăng buffer size và thêm pre-buffering
240
+ audio_queue = queue.Queue(maxsize=100)
241
+ PRE_BUFFER_SIZE = 3 # Chờ 3 chunks trước khi bắt đầu phát
242
 
243
+ end_event = threading.Event()
244
+ error_event = threading.Event()
245
+ error_msg = ""
246
+
247
+ def producer_thread():
248
+ nonlocal error_msg
249
+ try:
250
+ previous_tail = None
251
+ chunk_count = 0
252
+
253
+ for i, chunk_text in enumerate(text_chunks):
254
+ stream_gen = tts.infer_stream(chunk_text, ref_codes, ref_text_raw)
255
+
256
+ for part_idx, audio_part in enumerate(stream_gen):
257
+ if audio_part is None or len(audio_part) == 0:
258
+ continue
259
+
260
+ if previous_tail is not None and len(previous_tail) > 0:
261
+ overlap = min(len(previous_tail), len(audio_part), crossfade_samples)
262
+ if overlap > 0:
263
+ fade_out = np.linspace(1.0, 0.0, overlap, dtype=np.float32)
264
+ fade_in = np.linspace(0.0, 1.0, overlap, dtype=np.float32)
265
+
266
+ # Kết hợp phần overlap
267
+ blended = (audio_part[:overlap] * fade_in +
268
+ previous_tail[-overlap:] * fade_out)
269
+
270
+ processed = np.concatenate([
271
+ previous_tail[:-overlap] if len(previous_tail) > overlap else np.array([]),
272
+ blended,
273
+ audio_part[overlap:]
274
+ ])
275
+ else:
276
+ processed = np.concatenate([previous_tail, audio_part])
277
+
278
+ tail_size = min(crossfade_samples, len(processed))
279
+ previous_tail = processed[-tail_size:].copy()
280
+ output_chunk = processed[:-tail_size] if len(processed) > tail_size else processed
281
+ else:
282
+ tail_size = min(crossfade_samples, len(audio_part))
283
+ previous_tail = audio_part[-tail_size:].copy()
284
+ output_chunk = audio_part[:-tail_size] if len(audio_part) > tail_size else audio_part
285
+
286
+ if len(output_chunk) > 0:
287
+ audio_queue.put((sr, output_chunk))
288
+ chunk_count += 1
289
+
290
+ if previous_tail is not None and len(previous_tail) > 0:
291
+ audio_queue.put((sr, previous_tail))
292
+
293
+ except Exception as e:
294
+ import traceback
295
+ traceback.print_exc()
296
+ error_msg = str(e)
297
+ error_event.set()
298
+ finally:
299
+ end_event.set()
300
+ audio_queue.put(None)
301
+
302
+ threading.Thread(target=producer_thread, daemon=True).start()
303
+
304
+ yield (sr, np.zeros(int(sr * 0.05))), "🔄 Đang buffering..."
305
 
306
+ pre_buffer = []
307
+ while len(pre_buffer) < PRE_BUFFER_SIZE:
308
+ try:
309
+ item = audio_queue.get(timeout=5.0)
310
+ if item is None:
311
+ break
312
+ pre_buffer.append(item)
313
+ except queue.Empty:
314
+ if error_event.is_set():
315
+ yield None, f"❌ Lỗi: {error_msg}"
316
+ return
317
+ break
318
 
319
+ # Bắt đầu phát pre-buffer
320
+ full_audio_buffer = []
321
+ for sr, audio_data in pre_buffer:
322
+ full_audio_buffer.append(audio_data)
323
+ yield (sr, audio_data), "🔊 Đang phát..."
324
 
325
+ # Tiếp tục phát phần còn lại
326
+ while True:
327
+ try:
328
+ item = audio_queue.get(timeout=0.05)
329
+ if item is None:
330
+ break
331
+ sr, audio_data = item
332
+ full_audio_buffer.append(audio_data)
333
+ yield (sr, audio_data), "🔊 Đang phát..."
334
+ except queue.Empty:
335
+ if error_event.is_set():
336
+ yield None, f"❌ Lỗi: {error_msg}"
337
+ break
338
+ if end_event.is_set() and audio_queue.empty():
339
+ break
340
+ continue
341
 
342
+ # Lưu file hoàn chỉnh
343
+ if full_audio_buffer:
344
+ final_wav = np.concatenate(full_audio_buffer)
345
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
346
+ sf.write(tmp.name, final_wav, sr)
347
+ yield tmp.name, "✅ Hoàn tất Streaming!"
348
 
349
  # --- 4. UI SETUP ---
350
  theme = gr.themes.Ocean(
 
355
  ).set(
356
  button_primary_background_fill="linear-gradient(90deg, #6366f1 0%, #0ea5e9 100%)",
357
  button_primary_background_fill_hover="linear-gradient(90deg, #4f46e5 0%, #0284c7 100%)",
 
358
  )
359
 
 
360
  css = """
361
+ .container { max-width: 1400px; margin: auto; }
362
+ .header-box { text-align: center; margin-bottom: 25px; padding: 25px; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); border-radius: 12px; color: white; }
363
+ .header-title { font-size: 2.5rem; font-weight: 800; background: -webkit-linear-gradient(45deg, #60A5FA, #22D3EE); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  .status-box { font-weight: bold; text-align: center; border: none; background: transparent; }
 
 
 
 
 
 
 
 
 
 
365
  """
366
 
367
  EXAMPLES_LIST = [
368
+ ["Về miền Tây không chỉ để ngắm nhìn sông nước hữu tình, mà còn để cảm nhận tấm chân tình của người dân nơi đây.", "Vĩnh (nam miền Nam)"],
369
+ ["Hà Nội những ngày vào thu mang một vẻ đẹp trầm mặc và cổ kính đến lạ thường.", "Bình (nam miền Bắc)"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  ]
371
 
372
+ with gr.Blocks(theme=theme, css=css, title="VieNeu-TTS") as demo:
373
 
374
  with gr.Column(elem_classes="container"):
375
+ gr.HTML("""<div class="header-box"><div class="header-title">🦜 VieNeu-TTS Studio</div></div>""")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
 
377
+ # --- CONFIGURATION ---
378
+ with gr.Group():
379
+ with gr.Row():
380
+ backbone_select = gr.Dropdown(list(BACKBONE_CONFIGS.keys()), value="GGUF Q8", label="🦜 Backbone")
381
+ codec_select = gr.Dropdown(list(CODEC_CONFIGS.keys()), value="NeuCodec (Standard)", label="🎵 Codec")
382
+ device_choice = gr.Radio(["Auto", "CPU", "CUDA"], value="Auto", label="🖥️ Device")
 
 
 
 
383
 
 
384
  with gr.Row():
385
+ btn_load = gr.Button("🔄 Tải Model", variant="primary")
386
+ model_status = gr.Markdown("⏳ Chưa tải model.")
387
+
388
+ with gr.Row(elem_classes="container"):
389
+ # --- INPUT ---
390
+ with gr.Column(scale=3):
391
+ text_input = gr.Textbox(
392
+ label=f"Văn bản (Streaming hỗ trợ tới {MAX_TOTAL_CHARS_STREAMING} ký tự, chia chunk {MAX_CHARS_PER_CHUNK} ký tự)",
393
+ lines=4,
394
+ value="Hà Nội, trái tim của Việt Nam, là một thành phố ngàn năm văn hiến với bề dày lịch sử và văn hóa độc đáo. Bước chân trên những con phố cổ kính quanh Hồ Hoàn Kiếm, du khách như được du hành ngược thời gian, chiêm ngưỡng kiến trúc Pháp cổ điển hòa quyện với nét kiến trúc truyền thống Việt Nam. Mỗi con phố trong khu phố cổ mang một tên gọi đặc trưng, phản ánh nghề thủ công truyền thống từng thịnh hành nơi đây như phố Hàng Bạc, Hàng Đào, Hàng Mã. Ẩm thực Hà Nội cũng là một điểm nhấn đặc biệt, từ tô phở nóng hổi buổi sáng, bún chả thơm lừng trưa hè, đến chè Thái ngọt ngào chiều thu. Những món ăn dân dã này đã trở thành biểu tượng của văn hóa ẩm thực Việt, được cả thế giới yêu mến. Người Hà Nội nổi tiếng với tính cách hiền hòa, lịch thiệp nhưng cũng rất cầu toàn trong từng chi tiết nhỏ, từ cách pha trà sen cho đến cách chọn hoa sen tây để thưởng trà.",
395
+ )
396
 
 
397
  with gr.Tabs() as tabs:
398
+ with gr.TabItem("👤 Preset", id="preset_mode"):
399
+ initial_voices = get_voice_options("GGUF Q8")
400
+ default_voice = initial_voices[0] if initial_voices else None
401
+ voice_select = gr.Dropdown(initial_voices, value=default_voice, label="Giọng mẫu")
402
+ with gr.TabItem("🎙️ Custom", id="custom_mode"):
403
+ custom_audio = gr.Audio(label="File mẫu (.wav)", type="filepath")
404
+ custom_text = gr.Textbox(label="Lời thoại mẫu")
 
 
 
 
 
 
 
 
405
 
406
+ generation_mode = gr.Radio(
407
+ ["Standard (Một lần)", "Streaming (Từng đoạn)"],
408
+ value="Streaming (Từng đoạn)",
409
+ label="Chế độ sinh"
410
+ )
411
  current_mode = gr.Textbox(visible=False, value="preset_mode")
412
+ btn_generate = gr.Button("🎵 Bắt đầu", variant="primary", size="lg")
413
 
414
+ # --- OUTPUT ---
415
  with gr.Column(scale=2):
416
+ audio_output = gr.Audio(
417
+ label="Kết quả",
418
+ type="filepath",
419
+ autoplay=True,
420
+ show_download_button=True
421
+ )
422
+ status_output = gr.Textbox(label="Trạng thái", elem_classes="status-box")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
 
424
+ # --- EVENT HANDLERS ---
 
 
425
 
426
+ def update_info(backbone):
427
+ return f"Streaming: {'✅' if BACKBONE_CONFIGS[backbone]['supports_streaming'] else '❌'}"
428
+ backbone_select.change(update_info, backbone_select, model_status)
429
+ backbone_select.change(update_voice_dropdown, [backbone_select, voice_select], voice_select)
430
 
431
+ tabs.children[0].select(lambda: "preset_mode", outputs=current_mode)
432
+ tabs.children[1].select(lambda: "custom_mode", outputs=current_mode)
433
+
434
+ btn_load.click(load_model, [backbone_select, codec_select, device_choice], model_status)
 
 
 
435
 
436
  btn_generate.click(
437
  fn=synthesize_speech,
438
+ inputs=[text_input, voice_select, custom_audio, custom_text, current_mode, generation_mode],
439
  outputs=[audio_output, status_output]
440
  )
441
 
442
  if __name__ == "__main__":
443
+ demo.queue().launch(server_name="127.0.0.1", server_port=7860)
 
 
 
 
main.py CHANGED
@@ -3,7 +3,7 @@ import soundfile as sf
3
  import torch
4
  import os
5
 
6
- device = "cuda" if torch.cuda.is_available() else "cpu"
7
 
8
  input_texts = [
9
  "Các khóa học trực tuyến đang giúp học sinh tiếp cận kiến thức mọi lúc mọi nơi. Giáo viên sử dụng video, bài tập tương tác và thảo luận trực tuyến để nâng cao hiệu quả học tập.",
@@ -18,7 +18,7 @@ input_texts = [
18
  output_dir = "./output_audio"
19
  os.makedirs(output_dir, exist_ok=True)
20
 
21
- def main(backbone="pnnbao-ump/VieNeu-TTS", codec="neuphonic/neucodec"):
22
  """
23
  In the sample directory, there are wav files and txt files with matching names.
24
  These are pre-prepared reference files for testing with Vietnamese names:
@@ -41,6 +41,7 @@ def main(backbone="pnnbao-ump/VieNeu-TTS", codec="neuphonic/neucodec"):
41
  # Male voice (South accent)
42
  ref_audio_path = "./sample/Vĩnh (nam miền Nam).wav"
43
  ref_text_path = "./sample/Vĩnh (nam miền Nam).txt"
 
44
 
45
  # Female voice (South accent) - uncomment to use
46
  # ref_audio_path = "./sample/Đoan (nữ miền Nam).wav"
@@ -60,8 +61,12 @@ def main(backbone="pnnbao-ump/VieNeu-TTS", codec="neuphonic/neucodec"):
60
  codec_device=device
61
  )
62
 
63
- print("Encoding reference audio...")
64
- ref_codes = tts.encode_reference(ref_audio_path)
 
 
 
 
65
 
66
  # Generate speech for all input texts
67
  for i, text in enumerate(input_texts, 1):
 
3
  import torch
4
  import os
5
 
6
+ device = "cpu"
7
 
8
  input_texts = [
9
  "Các khóa học trực tuyến đang giúp học sinh tiếp cận kiến thức mọi lúc mọi nơi. Giáo viên sử dụng video, bài tập tương tác và thảo luận trực tuyến để nâng cao hiệu quả học tập.",
 
18
  output_dir = "./output_audio"
19
  os.makedirs(output_dir, exist_ok=True)
20
 
21
+ def main(backbone="pnnbao-ump/VieNeu-TTS-q4-gguf", codec="neuphonic/neucodec-onnx-decoder"):
22
  """
23
  In the sample directory, there are wav files and txt files with matching names.
24
  These are pre-prepared reference files for testing with Vietnamese names:
 
41
  # Male voice (South accent)
42
  ref_audio_path = "./sample/Vĩnh (nam miền Nam).wav"
43
  ref_text_path = "./sample/Vĩnh (nam miền Nam).txt"
44
+ ref_codes_path = "./sample/Vĩnh (nam miền Nam).pt"
45
 
46
  # Female voice (South accent) - uncomment to use
47
  # ref_audio_path = "./sample/Đoan (nữ miền Nam).wav"
 
61
  codec_device=device
62
  )
63
 
64
+ if codec == "neuphonic/neucodec-onnx-decoder":
65
+ print("Load reference codes...")
66
+ ref_codes = torch.load(ref_codes_path, map_location=device)
67
+ else:
68
+ print("Encoding reference audio...")
69
+ ref_codes = tts.encode_reference(ref_audio_path)
70
 
71
  # Generate speech for all input texts
72
  for i, text in enumerate(input_texts, 1):
pyproject.toml CHANGED
@@ -20,6 +20,8 @@ dependencies = [
20
  "neucodec>=0.0.4",
21
  "librosa>=0.11.0",
22
  "gradio>=5.49.1",
 
 
23
  ]
24
 
25
  [tool.uv.sources]
 
20
  "neucodec>=0.0.4",
21
  "librosa>=0.11.0",
22
  "gradio>=5.49.1",
23
+ "onnxruntime>=1.23.2",
24
+ "llama-cpp-python>=0.3.16",
25
  ]
26
 
27
  [tool.uv.sources]
sample/Bình (nam miền Bắc).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f896d618fc46c3e131eda7b4168e25e9c2fb2d7ea0e864bedff2577fbd0bd30
3
+ size 2089
sample/Dung (nữ miền Nam).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc4d65b6504470cb00e46763915060590595fbe4d47912eeacecd2bf1bade262
3
+ size 2153
sample/Hương (nữ miền Bắc).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:919035b7c762956a7d568cebc6e69fea22eb9be02bf906c1d32c1db1d8c7b9ff
3
+ size 2217
sample/Ly (nữ miền Bắc).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:69b6bc9bb1062122dc3755be907d87f232fa8be5129b54f6994dead35f4935c6
3
+ size 2153
sample/Nguyên (nam miền Nam).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e6ebaa0b2977589afa7e7f811b0553151bd8312c96a70b1b666bd9d0fd50edf
3
+ size 2345
sample/Ngọc (nữ miền Bắc).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:78ab670f177092dc8586e45536faea20fdb84471dc8d8a8b1b95dd76a4ed3d0d
3
+ size 2281
sample/Sơn (nam miền Nam).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:114cb04ee2357d06de2f038853bbeb0dc57fc8ed30e085118a9e0bf5a70f7857
3
+ size 2281
sample/Tuyên (nam miền Bắc).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e79eb6ee9cc7cd35cb4fbbef107249ed3209608b59644c52f55a34941a531873
3
+ size 2473
sample/Vĩnh (nam miền Nam).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c87342d3a6a8cbaaf2139c21e7554eea19aba6aa03248e4426238a1c2507e447
3
+ size 2217
sample/Đoan (nữ miền Nam).pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28b48dbae193adc88aa26243086ba3ce862def7035d9793613c2967df29f9afe
3
+ size 2793
utils/core_utils.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from typing import List
3
+
4
+ def split_text_into_chunks(text: str, max_chars: int = 256) -> List[str]:
5
+ """
6
+ Split raw text into chunks no longer than max_chars.
7
+ Preference is given to sentence boundaries; otherwise falls back to word-based splitting.
8
+ """
9
+ sentences = re.split(r"(?<=[\.\!\?\…])\s+", text.strip())
10
+ chunks: List[str] = []
11
+ buffer = ""
12
+
13
+ def flush_buffer():
14
+ nonlocal buffer
15
+ if buffer:
16
+ chunks.append(buffer.strip())
17
+ buffer = ""
18
+
19
+ for sentence in sentences:
20
+ sentence = sentence.strip()
21
+ if not sentence:
22
+ continue
23
+
24
+ if len(sentence) <= max_chars:
25
+ candidate = f"{buffer} {sentence}".strip() if buffer else sentence
26
+ if len(candidate) <= max_chars:
27
+ buffer = candidate
28
+ else:
29
+ flush_buffer()
30
+ buffer = sentence
31
+ continue
32
+
33
+ flush_buffer()
34
+ words = sentence.split()
35
+ current = ""
36
+ for word in words:
37
+ candidate = f"{current} {word}".strip() if current else word
38
+ if len(candidate) > max_chars and current:
39
+ chunks.append(current.strip())
40
+ current = word
41
+ else:
42
+ current = candidate
43
+ if current:
44
+ chunks.append(current.strip())
45
+
46
+ flush_buffer()
47
+ return [chunk for chunk in chunks if chunk]
uv.lock CHANGED
@@ -443,6 +443,18 @@ wheels = [
443
  { url = "https://download.pytorch.org/whl/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" },
444
  ]
445
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  [[package]]
447
  name = "csvw"
448
  version = "3.7.0"
@@ -508,6 +520,15 @@ wheels = [
508
  { url = "https://files.pythonhosted.org/packages/50/3d/9373ad9c56321fdab5b41197068e1d8c25883b3fea29dd361f9b55116869/dill-0.4.0-py3-none-any.whl", hash = "sha256:44f54bf6412c2c8464c14e8243eb163690a9800dbe2c367330883b19c7561049", size = 119668, upload-time = "2025-04-16T00:41:47.671Z" },
509
  ]
510
 
 
 
 
 
 
 
 
 
 
511
  [[package]]
512
  name = "dlinfo"
513
  version = "2.0.0"
@@ -573,6 +594,15 @@ wheels = [
573
  { url = "https://files.pythonhosted.org/packages/76/91/7216b27286936c16f5b4d0c530087e4a54eead683e6b0b73dd0c64844af6/filelock-3.20.0-py3-none-any.whl", hash = "sha256:339b4732ffda5cd79b13f4e2711a31b0365ce445d95d243bb996273d072546a2", size = 16054, upload-time = "2025-10-08T18:03:48.35Z" },
574
  ]
575
 
 
 
 
 
 
 
 
 
 
576
  [[package]]
577
  name = "frozendict"
578
  version = "2.4.6"
@@ -877,6 +907,18 @@ hf-transfer = [
877
  { name = "hf-transfer" },
878
  ]
879
 
 
 
 
 
 
 
 
 
 
 
 
 
880
  [[package]]
881
  name = "hyper-connections"
882
  version = "0.2.1"
@@ -1030,6 +1072,18 @@ wheels = [
1030
  { url = "https://files.pythonhosted.org/packages/b5/ba/c63c5786dfee4c3417094c4b00966e61e4a63efecee22cb7b4c0387dda83/librosa-0.11.0-py3-none-any.whl", hash = "sha256:0b6415c4fd68bff4c29288abe67c6d80b587e0e1e2cfb0aad23e4559504a7fa1", size = 260749, upload-time = "2025-03-11T15:09:52.982Z" },
1031
  ]
1032
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
  [[package]]
1034
  name = "llvmlite"
1035
  version = "0.45.1"
@@ -1612,6 +1666,33 @@ wheels = [
1612
  { url = "https://files.pythonhosted.org/packages/e3/94/1843518e420fa3ed6919835845df698c7e27e183cb997394e4a670973a65/omegaconf-2.3.0-py3-none-any.whl", hash = "sha256:7b4df175cdb08ba400f45cae3bdcae7ba8365db4d165fc65fd04b050ab63b46b", size = 79500, upload-time = "2022-12-08T20:59:19.686Z" },
1613
  ]
1614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1615
  [[package]]
1616
  name = "orjson"
1617
  version = "3.11.4"
@@ -1915,6 +1996,21 @@ wheels = [
1915
  { url = "https://files.pythonhosted.org/packages/5b/5a/bc7b4a4ef808fa59a816c17b20c4bef6884daebbdf627ff2a161da67da19/propcache-0.4.1-py3-none-any.whl", hash = "sha256:af2a6052aeb6cf17d3e46ee169099044fd8224cbaf75c76a2ef596e8163e2237", size = 13305, upload-time = "2025-10-08T19:49:00.792Z" },
1916
  ]
1917
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1918
  [[package]]
1919
  name = "psutil"
1920
  version = "7.1.2"
@@ -2107,6 +2203,15 @@ wheels = [
2107
  { url = "https://files.pythonhosted.org/packages/10/5e/1aa9a93198c6b64513c9d7752de7422c06402de6600a8767da1524f9570b/pyparsing-3.2.5-py3-none-any.whl", hash = "sha256:e38a4f02064cf41fe6593d328d0512495ad1f3d8a91c4f73fc401b3079a59a5e", size = 113890, upload-time = "2025-09-21T04:11:04.117Z" },
2108
  ]
2109
 
 
 
 
 
 
 
 
 
 
2110
  [[package]]
2111
  name = "python-dateutil"
2112
  version = "2.9.0.post0"
@@ -3120,7 +3225,9 @@ dependencies = [
3120
  { name = "gradio" },
3121
  { name = "huggingface-hub", extra = ["cli"] },
3122
  { name = "librosa" },
 
3123
  { name = "neucodec" },
 
3124
  { name = "phonemizer" },
3125
  { name = "torch" },
3126
  { name = "torchaudio" },
@@ -3132,7 +3239,9 @@ requires-dist = [
3132
  { name = "gradio", specifier = ">=5.49.1" },
3133
  { name = "huggingface-hub", extras = ["cli"], specifier = ">=0.36.0" },
3134
  { name = "librosa", specifier = ">=0.11.0" },
 
3135
  { name = "neucodec", specifier = ">=0.0.4" },
 
3136
  { name = "phonemizer", specifier = ">=3.3.0" },
3137
  { name = "torch", index = "https://download.pytorch.org/whl/cu118" },
3138
  { name = "torchaudio", index = "https://download.pytorch.org/whl/cu118" },
 
443
  { url = "https://download.pytorch.org/whl/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" },
444
  ]
445
 
446
+ [[package]]
447
+ name = "coloredlogs"
448
+ version = "15.0.1"
449
+ source = { registry = "https://pypi.org/simple" }
450
+ dependencies = [
451
+ { name = "humanfriendly" },
452
+ ]
453
+ sdist = { url = "https://files.pythonhosted.org/packages/cc/c7/eed8f27100517e8c0e6b923d5f0845d0cb99763da6fdee00478f91db7325/coloredlogs-15.0.1.tar.gz", hash = "sha256:7c991aa71a4577af2f82600d8f8f3a89f936baeaf9b50a9c197da014e5bf16b0", size = 278520, upload-time = "2021-06-11T10:22:45.202Z" }
454
+ wheels = [
455
+ { url = "https://files.pythonhosted.org/packages/a7/06/3d6badcf13db419e25b07041d9c7b4a2c331d3f4e7134445ec5df57714cd/coloredlogs-15.0.1-py2.py3-none-any.whl", hash = "sha256:612ee75c546f53e92e70049c9dbfcc18c935a2b9a53b66085ce9ef6a6e5c0934", size = 46018, upload-time = "2021-06-11T10:22:42.561Z" },
456
+ ]
457
+
458
  [[package]]
459
  name = "csvw"
460
  version = "3.7.0"
 
520
  { url = "https://files.pythonhosted.org/packages/50/3d/9373ad9c56321fdab5b41197068e1d8c25883b3fea29dd361f9b55116869/dill-0.4.0-py3-none-any.whl", hash = "sha256:44f54bf6412c2c8464c14e8243eb163690a9800dbe2c367330883b19c7561049", size = 119668, upload-time = "2025-04-16T00:41:47.671Z" },
521
  ]
522
 
523
+ [[package]]
524
+ name = "diskcache"
525
+ version = "5.6.3"
526
+ source = { registry = "https://pypi.org/simple" }
527
+ sdist = { url = "https://files.pythonhosted.org/packages/3f/21/1c1ffc1a039ddcc459db43cc108658f32c57d271d7289a2794e401d0fdb6/diskcache-5.6.3.tar.gz", hash = "sha256:2c3a3fa2743d8535d832ec61c2054a1641f41775aa7c556758a109941e33e4fc", size = 67916, upload-time = "2023-08-31T06:12:00.316Z" }
528
+ wheels = [
529
+ { url = "https://files.pythonhosted.org/packages/3f/27/4570e78fc0bf5ea0ca45eb1de3818a23787af9b390c0b0a0033a1b8236f9/diskcache-5.6.3-py3-none-any.whl", hash = "sha256:5e31b2d5fbad117cc363ebaf6b689474db18a1f6438bc82358b024abd4c2ca19", size = 45550, upload-time = "2023-08-31T06:11:58.822Z" },
530
+ ]
531
+
532
  [[package]]
533
  name = "dlinfo"
534
  version = "2.0.0"
 
594
  { url = "https://files.pythonhosted.org/packages/76/91/7216b27286936c16f5b4d0c530087e4a54eead683e6b0b73dd0c64844af6/filelock-3.20.0-py3-none-any.whl", hash = "sha256:339b4732ffda5cd79b13f4e2711a31b0365ce445d95d243bb996273d072546a2", size = 16054, upload-time = "2025-10-08T18:03:48.35Z" },
595
  ]
596
 
597
+ [[package]]
598
+ name = "flatbuffers"
599
+ version = "25.9.23"
600
+ source = { registry = "https://pypi.org/simple" }
601
+ sdist = { url = "https://files.pythonhosted.org/packages/9d/1f/3ee70b0a55137442038f2a33469cc5fddd7e0ad2abf83d7497c18a2b6923/flatbuffers-25.9.23.tar.gz", hash = "sha256:676f9fa62750bb50cf531b42a0a2a118ad8f7f797a511eda12881c016f093b12", size = 22067, upload-time = "2025-09-24T05:25:30.106Z" }
602
+ wheels = [
603
+ { url = "https://files.pythonhosted.org/packages/ee/1b/00a78aa2e8fbd63f9af08c9c19e6deb3d5d66b4dda677a0f61654680ee89/flatbuffers-25.9.23-py2.py3-none-any.whl", hash = "sha256:255538574d6cb6d0a79a17ec8bc0d30985913b87513a01cce8bcdb6b4c44d0e2", size = 30869, upload-time = "2025-09-24T05:25:28.912Z" },
604
+ ]
605
+
606
  [[package]]
607
  name = "frozendict"
608
  version = "2.4.6"
 
907
  { name = "hf-transfer" },
908
  ]
909
 
910
+ [[package]]
911
+ name = "humanfriendly"
912
+ version = "10.0"
913
+ source = { registry = "https://pypi.org/simple" }
914
+ dependencies = [
915
+ { name = "pyreadline3", marker = "sys_platform == 'win32'" },
916
+ ]
917
+ sdist = { url = "https://files.pythonhosted.org/packages/cc/3f/2c29224acb2e2df4d2046e4c73ee2662023c58ff5b113c4c1adac0886c43/humanfriendly-10.0.tar.gz", hash = "sha256:6b0b831ce8f15f7300721aa49829fc4e83921a9a301cc7f606be6686a2288ddc", size = 360702, upload-time = "2021-09-17T21:40:43.31Z" }
918
+ wheels = [
919
+ { url = "https://files.pythonhosted.org/packages/f0/0f/310fb31e39e2d734ccaa2c0fb981ee41f7bd5056ce9bc29b2248bd569169/humanfriendly-10.0-py2.py3-none-any.whl", hash = "sha256:1697e1a8a8f550fd43c2865cd84542fc175a61dcb779b6fee18cf6b6ccba1477", size = 86794, upload-time = "2021-09-17T21:40:39.897Z" },
920
+ ]
921
+
922
  [[package]]
923
  name = "hyper-connections"
924
  version = "0.2.1"
 
1072
  { url = "https://files.pythonhosted.org/packages/b5/ba/c63c5786dfee4c3417094c4b00966e61e4a63efecee22cb7b4c0387dda83/librosa-0.11.0-py3-none-any.whl", hash = "sha256:0b6415c4fd68bff4c29288abe67c6d80b587e0e1e2cfb0aad23e4559504a7fa1", size = 260749, upload-time = "2025-03-11T15:09:52.982Z" },
1073
  ]
1074
 
1075
+ [[package]]
1076
+ name = "llama-cpp-python"
1077
+ version = "0.3.16"
1078
+ source = { registry = "https://pypi.org/simple" }
1079
+ dependencies = [
1080
+ { name = "diskcache" },
1081
+ { name = "jinja2" },
1082
+ { name = "numpy" },
1083
+ { name = "typing-extensions" },
1084
+ ]
1085
+ sdist = { url = "https://files.pythonhosted.org/packages/e4/b4/c8cd17629ced0b9644a71d399a91145aedef109c0333443bef015e45b704/llama_cpp_python-0.3.16.tar.gz", hash = "sha256:34ed0f9bd9431af045bb63d9324ae620ad0536653740e9bb163a2e1fcb973be6", size = 50688636, upload-time = "2025-08-15T04:58:29.212Z" }
1086
+
1087
  [[package]]
1088
  name = "llvmlite"
1089
  version = "0.45.1"
 
1666
  { url = "https://files.pythonhosted.org/packages/e3/94/1843518e420fa3ed6919835845df698c7e27e183cb997394e4a670973a65/omegaconf-2.3.0-py3-none-any.whl", hash = "sha256:7b4df175cdb08ba400f45cae3bdcae7ba8365db4d165fc65fd04b050ab63b46b", size = 79500, upload-time = "2022-12-08T20:59:19.686Z" },
1667
  ]
1668
 
1669
+ [[package]]
1670
+ name = "onnxruntime"
1671
+ version = "1.23.2"
1672
+ source = { registry = "https://pypi.org/simple" }
1673
+ dependencies = [
1674
+ { name = "coloredlogs" },
1675
+ { name = "flatbuffers" },
1676
+ { name = "numpy" },
1677
+ { name = "packaging" },
1678
+ { name = "protobuf" },
1679
+ { name = "sympy" },
1680
+ ]
1681
+ wheels = [
1682
+ { url = "https://files.pythonhosted.org/packages/1b/9e/f748cd64161213adeef83d0cb16cb8ace1e62fa501033acdd9f9341fff57/onnxruntime-1.23.2-cp312-cp312-macosx_13_0_arm64.whl", hash = "sha256:b8f029a6b98d3cf5be564d52802bb50a8489ab73409fa9db0bf583eabb7c2321", size = 17195929, upload-time = "2025-10-22T03:47:36.24Z" },
1683
+ { url = "https://files.pythonhosted.org/packages/91/9d/a81aafd899b900101988ead7fb14974c8a58695338ab6a0f3d6b0100f30b/onnxruntime-1.23.2-cp312-cp312-macosx_13_0_x86_64.whl", hash = "sha256:218295a8acae83905f6f1aed8cacb8e3eb3bd7513a13fe4ba3b2664a19fc4a6b", size = 19157705, upload-time = "2025-10-22T03:46:40.415Z" },
1684
+ { url = "https://files.pythonhosted.org/packages/3c/35/4e40f2fba272a6698d62be2cd21ddc3675edfc1a4b9ddefcc4648f115315/onnxruntime-1.23.2-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:76ff670550dc23e58ea9bc53b5149b99a44e63b34b524f7b8547469aaa0dcb8c", size = 15226915, upload-time = "2025-10-22T03:46:27.773Z" },
1685
+ { url = "https://files.pythonhosted.org/packages/ef/88/9cc25d2bafe6bc0d4d3c1db3ade98196d5b355c0b273e6a5dc09c5d5d0d5/onnxruntime-1.23.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0f9b4ae77f8e3c9bee50c27bc1beede83f786fe1d52e99ac85aa8d65a01e9b77", size = 17382649, upload-time = "2025-10-22T03:47:02.782Z" },
1686
+ { url = "https://files.pythonhosted.org/packages/c0/b4/569d298f9fc4d286c11c45e85d9ffa9e877af12ace98af8cab52396e8f46/onnxruntime-1.23.2-cp312-cp312-win_amd64.whl", hash = "sha256:25de5214923ce941a3523739d34a520aac30f21e631de53bba9174dc9c004435", size = 13470528, upload-time = "2025-10-22T03:47:28.106Z" },
1687
+ { url = "https://files.pythonhosted.org/packages/3d/41/fba0cabccecefe4a1b5fc8020c44febb334637f133acefc7ec492029dd2c/onnxruntime-1.23.2-cp313-cp313-macosx_13_0_arm64.whl", hash = "sha256:2ff531ad8496281b4297f32b83b01cdd719617e2351ffe0dba5684fb283afa1f", size = 17196337, upload-time = "2025-10-22T03:46:35.168Z" },
1688
+ { url = "https://files.pythonhosted.org/packages/fe/f9/2d49ca491c6a986acce9f1d1d5fc2099108958cc1710c28e89a032c9cfe9/onnxruntime-1.23.2-cp313-cp313-macosx_13_0_x86_64.whl", hash = "sha256:162f4ca894ec3de1a6fd53589e511e06ecdc3ff646849b62a9da7489dee9ce95", size = 19157691, upload-time = "2025-10-22T03:46:43.518Z" },
1689
+ { url = "https://files.pythonhosted.org/packages/1c/a1/428ee29c6eaf09a6f6be56f836213f104618fb35ac6cc586ff0f477263eb/onnxruntime-1.23.2-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:45d127d6e1e9b99d1ebeae9bcd8f98617a812f53f46699eafeb976275744826b", size = 15226898, upload-time = "2025-10-22T03:46:30.039Z" },
1690
+ { url = "https://files.pythonhosted.org/packages/f2/2b/b57c8a2466a3126dbe0a792f56ad7290949b02f47b86216cd47d857e4b77/onnxruntime-1.23.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8bace4e0d46480fbeeb7bbe1ffe1f080e6663a42d1086ff95c1551f2d39e7872", size = 17382518, upload-time = "2025-10-22T03:47:05.407Z" },
1691
+ { url = "https://files.pythonhosted.org/packages/4a/93/aba75358133b3a941d736816dd392f687e7eab77215a6e429879080b76b6/onnxruntime-1.23.2-cp313-cp313-win_amd64.whl", hash = "sha256:1f9cc0a55349c584f083c1c076e611a7c35d5b867d5d6e6d6c823bf821978088", size = 13470276, upload-time = "2025-10-22T03:47:31.193Z" },
1692
+ { url = "https://files.pythonhosted.org/packages/7c/3d/6830fa61c69ca8e905f237001dbfc01689a4e4ab06147020a4518318881f/onnxruntime-1.23.2-cp313-cp313t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9d2385e774f46ac38f02b3a91a91e30263d41b2f1f4f26ae34805b2a9ddef466", size = 15229610, upload-time = "2025-10-22T03:46:32.239Z" },
1693
+ { url = "https://files.pythonhosted.org/packages/b6/ca/862b1e7a639460f0ca25fd5b6135fb42cf9deea86d398a92e44dfda2279d/onnxruntime-1.23.2-cp313-cp313t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e2b9233c4947907fd1818d0e581c049c41ccc39b2856cc942ff6d26317cee145", size = 17394184, upload-time = "2025-10-22T03:47:08.127Z" },
1694
+ ]
1695
+
1696
  [[package]]
1697
  name = "orjson"
1698
  version = "3.11.4"
 
1996
  { url = "https://files.pythonhosted.org/packages/5b/5a/bc7b4a4ef808fa59a816c17b20c4bef6884daebbdf627ff2a161da67da19/propcache-0.4.1-py3-none-any.whl", hash = "sha256:af2a6052aeb6cf17d3e46ee169099044fd8224cbaf75c76a2ef596e8163e2237", size = 13305, upload-time = "2025-10-08T19:49:00.792Z" },
1997
  ]
1998
 
1999
+ [[package]]
2000
+ name = "protobuf"
2001
+ version = "6.33.2"
2002
+ source = { registry = "https://pypi.org/simple" }
2003
+ sdist = { url = "https://files.pythonhosted.org/packages/34/44/e49ecff446afeec9d1a66d6bbf9adc21e3c7cea7803a920ca3773379d4f6/protobuf-6.33.2.tar.gz", hash = "sha256:56dc370c91fbb8ac85bc13582c9e373569668a290aa2e66a590c2a0d35ddb9e4", size = 444296, upload-time = "2025-12-06T00:17:53.311Z" }
2004
+ wheels = [
2005
+ { url = "https://files.pythonhosted.org/packages/bc/91/1e3a34881a88697a7354ffd177e8746e97a722e5e8db101544b47e84afb1/protobuf-6.33.2-cp310-abi3-win32.whl", hash = "sha256:87eb388bd2d0f78febd8f4c8779c79247b26a5befad525008e49a6955787ff3d", size = 425603, upload-time = "2025-12-06T00:17:41.114Z" },
2006
+ { url = "https://files.pythonhosted.org/packages/64/20/4d50191997e917ae13ad0a235c8b42d8c1ab9c3e6fd455ca16d416944355/protobuf-6.33.2-cp310-abi3-win_amd64.whl", hash = "sha256:fc2a0e8b05b180e5fc0dd1559fe8ebdae21a27e81ac77728fb6c42b12c7419b4", size = 436930, upload-time = "2025-12-06T00:17:43.278Z" },
2007
+ { url = "https://files.pythonhosted.org/packages/b2/ca/7e485da88ba45c920fb3f50ae78de29ab925d9e54ef0de678306abfbb497/protobuf-6.33.2-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:d9b19771ca75935b3a4422957bc518b0cecb978b31d1dd12037b088f6bcc0e43", size = 427621, upload-time = "2025-12-06T00:17:44.445Z" },
2008
+ { url = "https://files.pythonhosted.org/packages/7d/4f/f743761e41d3b2b2566748eb76bbff2b43e14d5fcab694f494a16458b05f/protobuf-6.33.2-cp39-abi3-manylinux2014_aarch64.whl", hash = "sha256:b5d3b5625192214066d99b2b605f5783483575656784de223f00a8d00754fc0e", size = 324460, upload-time = "2025-12-06T00:17:45.678Z" },
2009
+ { url = "https://files.pythonhosted.org/packages/b1/fa/26468d00a92824020f6f2090d827078c09c9c587e34cbfd2d0c7911221f8/protobuf-6.33.2-cp39-abi3-manylinux2014_s390x.whl", hash = "sha256:8cd7640aee0b7828b6d03ae518b5b4806fdfc1afe8de82f79c3454f8aef29872", size = 339168, upload-time = "2025-12-06T00:17:46.813Z" },
2010
+ { url = "https://files.pythonhosted.org/packages/56/13/333b8f421738f149d4fe5e49553bc2a2ab75235486259f689b4b91f96cec/protobuf-6.33.2-cp39-abi3-manylinux2014_x86_64.whl", hash = "sha256:1f8017c48c07ec5859106533b682260ba3d7c5567b1ca1f24297ce03384d1b4f", size = 323270, upload-time = "2025-12-06T00:17:48.253Z" },
2011
+ { url = "https://files.pythonhosted.org/packages/0e/15/4f02896cc3df04fc465010a4c6a0cd89810f54617a32a70ef531ed75d61c/protobuf-6.33.2-py3-none-any.whl", hash = "sha256:7636aad9bb01768870266de5dc009de2d1b936771b38a793f73cbbf279c91c5c", size = 170501, upload-time = "2025-12-06T00:17:52.211Z" },
2012
+ ]
2013
+
2014
  [[package]]
2015
  name = "psutil"
2016
  version = "7.1.2"
 
2203
  { url = "https://files.pythonhosted.org/packages/10/5e/1aa9a93198c6b64513c9d7752de7422c06402de6600a8767da1524f9570b/pyparsing-3.2.5-py3-none-any.whl", hash = "sha256:e38a4f02064cf41fe6593d328d0512495ad1f3d8a91c4f73fc401b3079a59a5e", size = 113890, upload-time = "2025-09-21T04:11:04.117Z" },
2204
  ]
2205
 
2206
+ [[package]]
2207
+ name = "pyreadline3"
2208
+ version = "3.5.4"
2209
+ source = { registry = "https://pypi.org/simple" }
2210
+ sdist = { url = "https://files.pythonhosted.org/packages/0f/49/4cea918a08f02817aabae639e3d0ac046fef9f9180518a3ad394e22da148/pyreadline3-3.5.4.tar.gz", hash = "sha256:8d57d53039a1c75adba8e50dd3d992b28143480816187ea5efbd5c78e6c885b7", size = 99839, upload-time = "2024-09-19T02:40:10.062Z" }
2211
+ wheels = [
2212
+ { url = "https://files.pythonhosted.org/packages/5a/dc/491b7661614ab97483abf2056be1deee4dc2490ecbf7bff9ab5cdbac86e1/pyreadline3-3.5.4-py3-none-any.whl", hash = "sha256:eaf8e6cc3c49bcccf145fc6067ba8643d1df34d604a1ec0eccbf7a18e6d3fae6", size = 83178, upload-time = "2024-09-19T02:40:08.598Z" },
2213
+ ]
2214
+
2215
  [[package]]
2216
  name = "python-dateutil"
2217
  version = "2.9.0.post0"
 
3225
  { name = "gradio" },
3226
  { name = "huggingface-hub", extra = ["cli"] },
3227
  { name = "librosa" },
3228
+ { name = "llama-cpp-python" },
3229
  { name = "neucodec" },
3230
+ { name = "onnxruntime" },
3231
  { name = "phonemizer" },
3232
  { name = "torch" },
3233
  { name = "torchaudio" },
 
3239
  { name = "gradio", specifier = ">=5.49.1" },
3240
  { name = "huggingface-hub", extras = ["cli"], specifier = ">=0.36.0" },
3241
  { name = "librosa", specifier = ">=0.11.0" },
3242
+ { name = "llama-cpp-python", specifier = ">=0.3.16" },
3243
  { name = "neucodec", specifier = ">=0.0.4" },
3244
+ { name = "onnxruntime", specifier = ">=1.23.2" },
3245
  { name = "phonemizer", specifier = ">=3.3.0" },
3246
  { name = "torch", index = "https://download.pytorch.org/whl/cu118" },
3247
  { name = "torchaudio", index = "https://download.pytorch.org/whl/cu118" },
vieneu_tts/vieneu_tts.py CHANGED
@@ -5,7 +5,7 @@ import numpy as np
5
  import torch
6
  from neucodec import NeuCodec, DistillNeuCodec
7
  from transformers import AutoTokenizer, AutoModelForCausalLM
8
- from utils.phonemize_text import phonemize_text, phonemize_with_dict
9
  import re
10
 
11
  def _linear_overlap_add(frames: list[np.ndarray], stride: int) -> np.ndarray:
@@ -110,7 +110,7 @@ class VieNeuTTS:
110
  except ImportError as e:
111
  raise ImportError(
112
  "Failed to import the onnx decoder."
113
- " Ensure you have onnxruntime installed as well as neucodec >= 0.0.4."
114
  ) from e
115
  self.codec = NeuCodecOnnxDecoder.from_pretrained(codec_repo)
116
  self._is_onnx_codec = True
@@ -276,7 +276,7 @@ class VieNeuTTS:
276
  for item in self.backbone(
277
  prompt,
278
  max_tokens=self.max_context,
279
- temperature=0.2,
280
  top_k=50,
281
  stop=["<|SPEECH_GENERATION_END|>"],
282
  stream=True
 
5
  import torch
6
  from neucodec import NeuCodec, DistillNeuCodec
7
  from transformers import AutoTokenizer, AutoModelForCausalLM
8
+ from utils.phonemize_text import phonemize_with_dict
9
  import re
10
 
11
  def _linear_overlap_add(frames: list[np.ndarray], stride: int) -> np.ndarray:
 
110
  except ImportError as e:
111
  raise ImportError(
112
  "Failed to import the onnx decoder."
113
+ "Ensure you have onnxruntime installed as well as neucodec >= 0.0.4."
114
  ) from e
115
  self.codec = NeuCodecOnnxDecoder.from_pretrained(codec_repo)
116
  self._is_onnx_codec = True
 
276
  for item in self.backbone(
277
  prompt,
278
  max_tokens=self.max_context,
279
+ temperature=1.0,
280
  top_k=50,
281
  stop=["<|SPEECH_GENERATION_END|>"],
282
  stream=True