Adoetz commited on
Commit
838abce
·
verified ·
1 Parent(s): af17061

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -58,15 +58,16 @@ def initialize_or_update_tts(model_name):
58
  if global_tts is None or model_name != current_model_name:
59
  print(f"Loading model: {model_name}")
60
  try:
61
- # Try loading the model with espeak
62
- global_tts = TTS(model_name=model_name, progress_bar=True)
63
- except Exception as e:
64
- print(f"Error loading model with espeak: {e}")
65
- print("Falling back to gruut phonemizer...")
66
- # Load the model with gruut phonemizer
67
  global_tts = TTS(model_name=model_name, progress_bar=True)
 
 
68
  if hasattr(global_tts.synthesizer, 'phonemizer'):
69
  global_tts.synthesizer.phonemizer = "gruut"
 
 
 
 
70
 
71
  global_tts.to(device)
72
  current_model_name = model_name
@@ -78,6 +79,8 @@ def generate_tts_audio(text, model_name, voice_choice, speaker_name=None, wav_fi
78
  try:
79
  # Initialize or update the TTS model
80
  tts = initialize_or_update_tts(model_name)
 
 
81
 
82
  # Determine the reference audio file
83
  if voice_choice == "existing_speaker":
 
58
  if global_tts is None or model_name != current_model_name:
59
  print(f"Loading model: {model_name}")
60
  try:
61
+ # Load the model with explicit phonemizer configuration
 
 
 
 
 
62
  global_tts = TTS(model_name=model_name, progress_bar=True)
63
+
64
+ # Force the use of gruut phonemizer
65
  if hasattr(global_tts.synthesizer, 'phonemizer'):
66
  global_tts.synthesizer.phonemizer = "gruut"
67
+ print("Using gruut phonemizer.")
68
+ except Exception as e:
69
+ print(f"Error loading model: {e}")
70
+ return None
71
 
72
  global_tts.to(device)
73
  current_model_name = model_name
 
79
  try:
80
  # Initialize or update the TTS model
81
  tts = initialize_or_update_tts(model_name)
82
+ if tts is None:
83
+ return "Error: Failed to load the TTS model.", None
84
 
85
  # Determine the reference audio file
86
  if voice_choice == "existing_speaker":