import os, traceback
from TTS.api import TTS

out='whisper_project/dub_female_xtts_es.wav'
speaker='whisper_project/ref_female_es.wav'
text='Hola, esta es una prueba de clonación usando xtts_v2 en español latino.'
model='tts_models/multilingual/multi-dataset/xtts_v2'

try:
    print('Cargando modelo:', model)
    tts = TTS(model_name=model, progress_bar=True, gpu=False)
    print('Llamando a tts_to_file con speaker_wav=', speaker)
    tts.tts_to_file(text=text, file_path=out, speaker_wav=speaker, language='es')
    print('Generado:', out, 'size=', os.path.getsize(out))
except Exception as e:
    print('Error durante la clonación:')
    traceback.print_exc()
