waxz commited on
Commit
24244a4
·
1 Parent(s): 367e4d1

add unsuppoterd text preprocess

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -190,8 +190,9 @@ class StreamingEngine:
190
 
191
  print(f"Loading Supertonic model...")
192
  try:
193
- self.model = TTS(auto_download=True)
194
- self.sample_rate = self.model.sample_rate
 
195
  print(f"Model Loaded. Rate: {self.sample_rate}")
196
  except Exception as e:
197
  print(f"Error initializing model: {e}")
@@ -211,13 +212,13 @@ class StreamingEngine:
211
  # 2. Try to get style
212
  try:
213
  # Note: We rely on supertonic throwing an error if name is invalid
214
- style = self.model.get_voice_style(voice_name=target_name)
215
  return style, target_name
216
  except Exception:
217
  # 3. Fallback
218
  print(f"WARNING: Voice '{voice_name}' (mapped to '{target_name}') not found. Using '{self.default_voice}'.")
219
  try:
220
- style = self.model.get_voice_style(voice_name=self.default_voice)
221
  return style, self.default_voice
222
  except Exception as e:
223
  print(f"CRITICAL: Default voice '{self.default_voice}' also failed.")
@@ -234,6 +235,21 @@ class StreamingEngine:
234
 
235
  yield create_wav_header(self.sample_rate)
236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  #chunks = split_text_into_sentences(text)
238
  chunks = split_text_into_sentences(text, min_chunk_size=150)
239
 
@@ -249,7 +265,7 @@ class StreamingEngine:
249
  async with self.lock:
250
  audio_float, _ = await loop.run_in_executor(
251
  None,
252
- self.model.synthesize,
253
  chunk,
254
  style
255
  # speed # Add speed here if your supertonic version supports it
 
190
 
191
  print(f"Loading Supertonic model...")
192
  try:
193
+ self.tts = TTS(auto_download=True)
194
+ self.text_processor = self.tts.model.text_processor
195
+ self.sample_rate = self.tts.sample_rate
196
  print(f"Model Loaded. Rate: {self.sample_rate}")
197
  except Exception as e:
198
  print(f"Error initializing model: {e}")
 
212
  # 2. Try to get style
213
  try:
214
  # Note: We rely on supertonic throwing an error if name is invalid
215
+ style = self.tts.get_voice_style(voice_name=target_name)
216
  return style, target_name
217
  except Exception:
218
  # 3. Fallback
219
  print(f"WARNING: Voice '{voice_name}' (mapped to '{target_name}') not found. Using '{self.default_voice}'.")
220
  try:
221
+ style = self.tts.get_voice_style(voice_name=self.default_voice)
222
  return style, self.default_voice
223
  except Exception as e:
224
  print(f"CRITICAL: Default voice '{self.default_voice}' also failed.")
 
235
 
236
  yield create_wav_header(self.sample_rate)
237
 
238
+
239
+ is_valid, unsupported = self.text_processor.validate_text(text)
240
+
241
+ if not is_valid:
242
+ print(f" ⚠️ Contains {len(unsupported)} unsupported character(s): {unsupported[:5]}")
243
+ pattern = f"[{re.escape(''.join(unsupported))}]"
244
+ preprocessed = re.sub(pattern, "", text) #self.text_processor._preprocess_text(text)
245
+ if preprocessed != text:
246
+ print(f" After preprocessing: {preprocessed[:50]}...")
247
+ text = preprocessed
248
+
249
+ else:
250
+ print(" ✓ All characters supported")
251
+
252
+
253
  #chunks = split_text_into_sentences(text)
254
  chunks = split_text_into_sentences(text, min_chunk_size=150)
255
 
 
265
  async with self.lock:
266
  audio_float, _ = await loop.run_in_executor(
267
  None,
268
+ self.tts.synthesize,
269
  chunk,
270
  style
271
  # speed # Add speed here if your supertonic version supports it