Spaces:
Configuration error
Configuration error
File size: 1,561 Bytes
b65e164 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#\!/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()
|