Spaces:
Configuration error
Configuration error
#\!/usr/bin/env python3 | |
import os | |
import sys | |
# Configurar ambiente | |
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com' | |
try: | |
from cosyvoice.cli.cosyvoice import CosyVoice | |
import torchaudio | |
import torch | |
print("Iniciando teste de TTS...") | |
# Usar o modelo direto que funcionou antes | |
model_path = 'pretrained_models/CosyVoice-300M-direct' | |
if not os.path.exists(model_path): | |
print(f"Erro: Modelo não encontrado em {model_path}") | |
sys.exit(1) | |
# Inicializar modelo | |
print("Carregando modelo CosyVoice...") | |
cosyvoice = CosyVoice(model_path, load_jit=False, load_trt=False, fp16=False) | |
# Texto para síntese | |
text = "Olá\! Este é um teste do CosyVoice. A síntese de voz está funcionando corretamente." | |
prompt_text = "Hello, this is a test of speech synthesis." | |
print(f"Texto: {text}") | |
print("Gerando áudio...") | |
# Gerar áudio | |
output_file = "teste_final_audio.wav" | |
for i, j in enumerate(cosyvoice.inference_zero_shot(text, prompt_text, None, stream=False)): | |
torchaudio.save(output_file, j['tts_speech'], cosyvoice.sample_rate) | |
print(f"Áudio salvo em: {output_file}") | |
break | |
# Verificar arquivo | |
if os.path.exists(output_file): | |
size = os.path.getsize(output_file) / 1024 | |
print(f"Arquivo gerado com sucesso\! Tamanho: {size:.1f} KB") | |
else: | |
print("Erro: Arquivo não foi gerado") | |
except Exception as e: | |
print(f"Erro: {e}") | |
import traceback | |
traceback.print_exc() | |