Update app.py
Browse files
app.py
CHANGED
|
@@ -223,8 +223,8 @@ def save_wav(audio, file_path):
|
|
| 223 |
print(f"β Failed to save WAV: {e}")
|
| 224 |
return False
|
| 225 |
|
| 226 |
-
def load_tts_model():
|
| 227 |
-
"""Load TTS model
|
| 228 |
global tts, model_loaded, current_model, voice_cloning_supported, model_loading, model_load_attempts
|
| 229 |
|
| 230 |
if model_loading:
|
|
@@ -245,30 +245,81 @@ def load_tts_model():
|
|
| 245 |
sys.stdin = StringIO('y\n')
|
| 246 |
|
| 247 |
try:
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
# Test the model
|
| 254 |
test_path = "/tmp/test_output.wav"
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
if os.path.exists(test_path):
|
| 258 |
os.remove(test_path)
|
| 259 |
-
print("β
|
| 260 |
else:
|
| 261 |
raise Exception("Test failed - no file created")
|
| 262 |
|
| 263 |
model_loaded = True
|
| 264 |
-
current_model = "
|
| 265 |
-
voice_cloning_supported = False
|
| 266 |
-
print("β
Tacotron2 model loaded successfully!")
|
| 267 |
return True
|
| 268 |
|
| 269 |
except Exception as e:
|
| 270 |
-
print(f"β
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
finally:
|
| 274 |
sys.stdin = old_stdin
|
|
|
|
| 223 |
print(f"β Failed to save WAV: {e}")
|
| 224 |
return False
|
| 225 |
|
| 226 |
+
def load_tts_model(voice_style="default"):
|
| 227 |
+
"""Load TTS model with different voice options"""
|
| 228 |
global tts, model_loaded, current_model, voice_cloning_supported, model_loading, model_load_attempts
|
| 229 |
|
| 230 |
if model_loading:
|
|
|
|
| 245 |
sys.stdin = StringIO('y\n')
|
| 246 |
|
| 247 |
try:
|
| 248 |
+
# Different models with different voice characteristics
|
| 249 |
+
model_options = {
|
| 250 |
+
"male_deep": {
|
| 251 |
+
"name": "tts_models/en/vctk/vits",
|
| 252 |
+
"description": "VITS - Multiple speakers (male/female options)",
|
| 253 |
+
"speaker": "p225" # Male voice
|
| 254 |
+
},
|
| 255 |
+
"male_medium": {
|
| 256 |
+
"name": "tts_models/en/vctk/vits",
|
| 257 |
+
"description": "VITS - Multiple speakers",
|
| 258 |
+
"speaker": "p226" # Male voice
|
| 259 |
+
},
|
| 260 |
+
"female_1": {
|
| 261 |
+
"name": "tts_models/en/vctk/vits",
|
| 262 |
+
"description": "VITS - Multiple speakers",
|
| 263 |
+
"speaker": "p227" # Female voice
|
| 264 |
+
},
|
| 265 |
+
"female_2": {
|
| 266 |
+
"name": "tts_models/en/vctk/vits",
|
| 267 |
+
"description": "VITS - Multiple speakers",
|
| 268 |
+
"speaker": "p228" # Female voice
|
| 269 |
+
},
|
| 270 |
+
"default_female": {
|
| 271 |
+
"name": "tts_models/en/ljspeech/tacotron2-DDC",
|
| 272 |
+
"description": "Tacotron2 - Default female (current)",
|
| 273 |
+
"speaker": None
|
| 274 |
+
},
|
| 275 |
+
"clear_male": {
|
| 276 |
+
"name": "tts_models/en/ek1/tacotron2",
|
| 277 |
+
"description": "Tacotron2 - Clear male voice",
|
| 278 |
+
"speaker": None
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
|
| 282 |
+
selected_model = model_options.get(voice_style, model_options["default_female"])
|
| 283 |
+
|
| 284 |
+
print(f"π Loading {selected_model['description']}...")
|
| 285 |
+
|
| 286 |
+
# Load the selected model
|
| 287 |
+
tts = TTS(selected_model["name"]).to(DEVICE)
|
| 288 |
|
| 289 |
# Test the model
|
| 290 |
test_path = "/tmp/test_output.wav"
|
| 291 |
+
|
| 292 |
+
if selected_model["speaker"]:
|
| 293 |
+
# For VITS model with speaker selection
|
| 294 |
+
tts.tts_to_file(
|
| 295 |
+
text="Test voice",
|
| 296 |
+
file_path=test_path,
|
| 297 |
+
speaker=selected_model["speaker"]
|
| 298 |
+
)
|
| 299 |
+
else:
|
| 300 |
+
# For standard models
|
| 301 |
+
tts.tts_to_file(text="Test voice", file_path=test_path)
|
| 302 |
|
| 303 |
if os.path.exists(test_path):
|
| 304 |
os.remove(test_path)
|
| 305 |
+
print(f"β
{selected_model['description']} loaded successfully!")
|
| 306 |
else:
|
| 307 |
raise Exception("Test failed - no file created")
|
| 308 |
|
| 309 |
model_loaded = True
|
| 310 |
+
current_model = selected_model["name"]
|
| 311 |
+
voice_cloning_supported = False
|
|
|
|
| 312 |
return True
|
| 313 |
|
| 314 |
except Exception as e:
|
| 315 |
+
print(f"β Model loading failed: {e}")
|
| 316 |
+
# Fallback to default
|
| 317 |
+
print("π Falling back to default Tacotron2...")
|
| 318 |
+
tts = TTS("tts_models/en/ljspeech/tacotron2-DDC").to(DEVICE)
|
| 319 |
+
model_loaded = True
|
| 320 |
+
current_model = "tts_models/en/ljspeech/tacotron2-DDC"
|
| 321 |
+
voice_cloning_supported = False
|
| 322 |
+
return True
|
| 323 |
|
| 324 |
finally:
|
| 325 |
sys.stdin = old_stdin
|