tonyshark commited on
Commit
e79f3e0
·
verified ·
1 Parent(s): 715f74a

Upload 2 files

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -8,10 +8,10 @@ import librosa
8
  from transformers import pipeline
9
 
10
  # ---------------------------
11
- # Load HF TTS model (hexgrad/styletts2)
12
  # ---------------------------
13
  SR_OUT = 24000
14
- tts_pipe = pipeline("text-to-speech", model="hexgrad/styletts2")
15
 
16
  # ---------------------------
17
  # Audio helpers
@@ -47,7 +47,7 @@ def plot_waveforms(clean, processed, sr=SR_OUT):
47
  t_clean = np.arange(len(clean)) / sr
48
  t_proc = np.arange(len(processed)) / sr
49
  axes[0].plot(t_clean, clean, color="blue")
50
- axes[0].set_title("Waveform sạch (hexgrad/styletts2)")
51
  axes[1].plot(t_proc, processed, color="red")
52
  axes[1].set_title("Waveform sau khi áp môi trường/noise")
53
  axes[1].set_xlabel("Thời gian (s)")
@@ -60,28 +60,11 @@ def plot_waveforms(clean, processed, sr=SR_OUT):
60
  TAG_LIST = {
61
  "laugh": "😆 Cười thoải mái",
62
  "whisper": "🤫 Thì thầm",
63
- "naughty": "😏 Tinh nghịch",
64
  "giggle": "😂 Cười rúc rích",
65
- "tease": "😉 Trêu chọc",
66
- "smirk": "😼 Đắc ý",
67
  "surprise": "😲 Ngạc nhiên",
68
- "shock": "😱 Hoảng hốt",
69
- "romantic": "❤️ Lãng mạn",
70
- "shy": "🫣 Bẽn lẽn",
71
- "excited": "🤩 Phấn khích",
72
- "curious": "🧐 Tò mò",
73
- "discover": "✨ Phát hiện",
74
- "blush": "🌸 Ngượng ngùng",
75
- "angry": "😡 Giận dữ",
76
  "sad": "😢 Buồn",
77
  "happy": "😊 Vui vẻ",
78
- "fear": "😨 Sợ hãi",
79
- "confident": "😎 Tự tin",
80
- "serious": "😐 Nghiêm túc",
81
- "tired": "🥱 Mệt mỏi",
82
- "cry": "😭 Khóc",
83
- "love": "😍 Yêu thương",
84
- "disgust": "🤢 Ghê tởm",
85
  }
86
  TAG_PATTERN = r"(<\/?(?:" + "|".join(TAG_LIST.keys()) + ")>)"
87
 
@@ -96,8 +79,8 @@ def synthesize(text, env, snr_db=10):
96
  if not tok or tok.isspace():
97
  continue
98
  if tok.startswith("<") and tok.endswith(">"):
99
- # Model hexgrad/styletts2 chưa hỗ trợ style embedding,
100
- # nên tags chỉ chia đoạn text.
101
  continue
102
  else:
103
  result = tts_pipe(text=tok)
@@ -133,20 +116,20 @@ def synthesize(text, env, snr_db=10):
133
  return (SR_OUT, processed), fig, (SR_OUT, clean_audio)
134
 
135
  # ---------------------------
136
- # Examples
137
  # ---------------------------
138
  EXAMPLES = [
139
  "Xin chào <whisper> tôi nói nhỏ </whisper> rồi <laugh> bật cười </laugh>.",
140
  "Tôi cảm thấy <happy> vui </happy> nhưng cũng <sad> buồn </sad>.",
141
- "Khi <surprise> bất ngờ </surprise> tôi <shock> hoảng hốt </shock>.",
142
  ]
143
 
144
  # ---------------------------
145
  # Gradio UI
146
  # ---------------------------
147
  with gr.Blocks() as demo:
148
- gr.Markdown("# 🎙️ hexgrad/styletts2 + Tags + Environment + Waveform Preview")
149
- gr.Markdown("Dùng model `hexgrad/styletts2` (giọng LibriTTS, mặc định). Tags chia đoạn text.")
150
 
151
  with gr.Accordion("📑 Danh sách Tags + Emoji", open=False):
152
  md = "| Tag | Ý nghĩa |\n|-----|----------|\n"
 
8
  from transformers import pipeline
9
 
10
  # ---------------------------
11
+ # Load HF TTS model (ak36/styletts2)
12
  # ---------------------------
13
  SR_OUT = 24000
14
+ tts_pipe = pipeline("text-to-speech", model="ak36/styletts2")
15
 
16
  # ---------------------------
17
  # Audio helpers
 
47
  t_clean = np.arange(len(clean)) / sr
48
  t_proc = np.arange(len(processed)) / sr
49
  axes[0].plot(t_clean, clean, color="blue")
50
+ axes[0].set_title("Waveform sạch (ak36/styletts2)")
51
  axes[1].plot(t_proc, processed, color="red")
52
  axes[1].set_title("Waveform sau khi áp môi trường/noise")
53
  axes[1].set_xlabel("Thời gian (s)")
 
60
  TAG_LIST = {
61
  "laugh": "😆 Cười thoải mái",
62
  "whisper": "🤫 Thì thầm",
 
63
  "giggle": "😂 Cười rúc rích",
 
 
64
  "surprise": "😲 Ngạc nhiên",
 
 
 
 
 
 
 
 
65
  "sad": "😢 Buồn",
66
  "happy": "😊 Vui vẻ",
67
+ "angry": "😡 Giận dữ",
 
 
 
 
 
 
68
  }
69
  TAG_PATTERN = r"(<\/?(?:" + "|".join(TAG_LIST.keys()) + ")>)"
70
 
 
79
  if not tok or tok.isspace():
80
  continue
81
  if tok.startswith("<") and tok.endswith(">"):
82
+ # Model ak36/styletts2 chưa hỗ trợ style embedding riêng,
83
+ # nên tags chỉ chia text thành đoạn.
84
  continue
85
  else:
86
  result = tts_pipe(text=tok)
 
116
  return (SR_OUT, processed), fig, (SR_OUT, clean_audio)
117
 
118
  # ---------------------------
119
+ # Example texts
120
  # ---------------------------
121
  EXAMPLES = [
122
  "Xin chào <whisper> tôi nói nhỏ </whisper> rồi <laugh> bật cười </laugh>.",
123
  "Tôi cảm thấy <happy> vui </happy> nhưng cũng <sad> buồn </sad>.",
124
+ "Khi <surprise> bất ngờ </surprise> tôi <angry> giận dữ </angry>.",
125
  ]
126
 
127
  # ---------------------------
128
  # Gradio UI
129
  # ---------------------------
130
  with gr.Blocks() as demo:
131
+ gr.Markdown("# 🎙️ ak36/styletts2 + Tags + Environment + Waveform Preview")
132
+ gr.Markdown("Dùng model `ak36/styletts2` (giọng LibriTTS mặc định). Tags chia text thành đoạn.")
133
 
134
  with gr.Accordion("📑 Danh sách Tags + Emoji", open=False):
135
  md = "| Tag | Ý nghĩa |\n|-----|----------|\n"