Spaces:
Configuration error
Configuration error
Marcos Remar
commited on
Commit
·
b65e164
1
Parent(s):
08991d5
Add test scripts for CosyVoice 1.0 (300M model)
Browse files- english_tts_test_timed.py +76 -0
- quick_test_when_ready.sh +24 -0
- quick_tts_test.py +50 -0
- test_audio_timed.py +61 -0
- test_tts_simple.py +31 -0
english_tts_test_timed.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#\!/usr/bin/env python3
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
import time
|
5 |
+
|
6 |
+
# Configurar ambiente
|
7 |
+
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
|
8 |
+
|
9 |
+
print("=== CosyVoice English TTS Test with Timing ===")
|
10 |
+
print()
|
11 |
+
|
12 |
+
start_time = time.time()
|
13 |
+
|
14 |
+
try:
|
15 |
+
from cosyvoice.cli.cosyvoice import CosyVoice
|
16 |
+
import torchaudio
|
17 |
+
|
18 |
+
model_path = 'pretrained_models/CosyVoice-300M-direct'
|
19 |
+
|
20 |
+
# Verificar se o modelo existe
|
21 |
+
if not os.path.exists(model_path):
|
22 |
+
print(f"❌ Error: Model not found at {model_path}")
|
23 |
+
sys.exit(1)
|
24 |
+
|
25 |
+
# Medir tempo de carregamento do modelo
|
26 |
+
load_start = time.time()
|
27 |
+
print("Loading CosyVoice model...")
|
28 |
+
cosyvoice = CosyVoice(model_path, load_jit=False, load_trt=False, fp16=False)
|
29 |
+
load_time = time.time() - load_start
|
30 |
+
print(f"✅ Model loaded in {load_time:.2f} seconds")
|
31 |
+
print()
|
32 |
+
|
33 |
+
# Texto em inglês para síntese
|
34 |
+
text = "Hello\! This is a test of the CosyVoice text-to-speech system. The synthesis is working perfectly and generating high quality audio."
|
35 |
+
prompt_text = "Welcome to the speech synthesis demonstration."
|
36 |
+
|
37 |
+
print(f"Text: {text}")
|
38 |
+
print(f"Prompt: {prompt_text}")
|
39 |
+
print()
|
40 |
+
|
41 |
+
# Medir tempo de geração
|
42 |
+
gen_start = time.time()
|
43 |
+
print("Generating audio...")
|
44 |
+
|
45 |
+
output_file = "english_test_output.wav"
|
46 |
+
for i, j in enumerate(cosyvoice.inference_zero_shot(text, prompt_text, None, stream=False)):
|
47 |
+
torchaudio.save(output_file, j['tts_speech'], cosyvoice.sample_rate)
|
48 |
+
break
|
49 |
+
|
50 |
+
gen_time = time.time() - gen_start
|
51 |
+
print(f"✅ Audio generated in {gen_time:.2f} seconds")
|
52 |
+
|
53 |
+
# Verificar arquivo gerado
|
54 |
+
if os.path.exists(output_file):
|
55 |
+
size = os.path.getsize(output_file)
|
56 |
+
duration = j['tts_speech'].shape[1] / cosyvoice.sample_rate
|
57 |
+
print()
|
58 |
+
print(f"📊 File statistics:")
|
59 |
+
print(f" - Filename: {output_file}")
|
60 |
+
print(f" - Size: {size/1024:.1f} KB")
|
61 |
+
print(f" - Duration: {duration:.2f} seconds")
|
62 |
+
print(f" - Sample rate: {cosyvoice.sample_rate} Hz")
|
63 |
+
|
64 |
+
total_time = time.time() - start_time
|
65 |
+
print()
|
66 |
+
print(f"⏱️ Total execution time: {total_time:.2f} seconds")
|
67 |
+
print(f" - Model loading: {load_time:.2f}s ({load_time/total_time*100:.1f}%)")
|
68 |
+
print(f" - Audio generation: {gen_time:.2f}s ({gen_time/total_time*100:.1f}%)")
|
69 |
+
|
70 |
+
except Exception as e:
|
71 |
+
print(f"❌ Error: {e}")
|
72 |
+
import traceback
|
73 |
+
traceback.print_exc()
|
74 |
+
|
75 |
+
total_time = time.time() - start_time
|
76 |
+
print(f"\nTotal time before error: {total_time:.2f} seconds")
|
quick_test_when_ready.sh
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#\!/bin/bash
|
2 |
+
# Script para testar CosyVoice2-0.5B quando o download terminar
|
3 |
+
|
4 |
+
echo "Verificando se o modelo CosyVoice2-0.5B está completo..."
|
5 |
+
|
6 |
+
if [ -f "pretrained_models/CosyVoice2-0.5B/llm.pt" ]; then
|
7 |
+
echo "✅ Modelo baixado\! Executando teste..."
|
8 |
+
python3 test_cosyvoice2_english.py
|
9 |
+
|
10 |
+
if [ -f "cosyvoice2_english_test.wav" ]; then
|
11 |
+
echo ""
|
12 |
+
echo "📊 Áudio gerado com sucesso\!"
|
13 |
+
ls -lh cosyvoice2_english_test.wav
|
14 |
+
echo ""
|
15 |
+
echo "Para baixar o áudio:"
|
16 |
+
echo "scp -P 40053 -i ~/.ssh/id_ed25519 [email protected]:/root/CosyVoice/cosyvoice2_english_test.wav ."
|
17 |
+
fi
|
18 |
+
else
|
19 |
+
echo "⏳ Download ainda em progresso..."
|
20 |
+
echo "Arquivos atuais:"
|
21 |
+
du -sh pretrained_models/CosyVoice2-0.5B/
|
22 |
+
echo ""
|
23 |
+
echo "Execute novamente em alguns minutos."
|
24 |
+
fi
|
quick_tts_test.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#\!/usr/bin/env python3
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
|
5 |
+
# Configurar ambiente
|
6 |
+
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
|
7 |
+
|
8 |
+
try:
|
9 |
+
from cosyvoice.cli.cosyvoice import CosyVoice
|
10 |
+
import torchaudio
|
11 |
+
import torch
|
12 |
+
|
13 |
+
print("Iniciando teste de TTS...")
|
14 |
+
|
15 |
+
# Usar o modelo direto que funcionou antes
|
16 |
+
model_path = 'pretrained_models/CosyVoice-300M-direct'
|
17 |
+
|
18 |
+
if not os.path.exists(model_path):
|
19 |
+
print(f"Erro: Modelo não encontrado em {model_path}")
|
20 |
+
sys.exit(1)
|
21 |
+
|
22 |
+
# Inicializar modelo
|
23 |
+
print("Carregando modelo CosyVoice...")
|
24 |
+
cosyvoice = CosyVoice(model_path, load_jit=False, load_trt=False, fp16=False)
|
25 |
+
|
26 |
+
# Texto para síntese
|
27 |
+
text = "Olá\! Este é um teste do CosyVoice. A síntese de voz está funcionando corretamente."
|
28 |
+
prompt_text = "Hello, this is a test of speech synthesis."
|
29 |
+
|
30 |
+
print(f"Texto: {text}")
|
31 |
+
print("Gerando áudio...")
|
32 |
+
|
33 |
+
# Gerar áudio
|
34 |
+
output_file = "teste_final_audio.wav"
|
35 |
+
for i, j in enumerate(cosyvoice.inference_zero_shot(text, prompt_text, None, stream=False)):
|
36 |
+
torchaudio.save(output_file, j['tts_speech'], cosyvoice.sample_rate)
|
37 |
+
print(f"Áudio salvo em: {output_file}")
|
38 |
+
break
|
39 |
+
|
40 |
+
# Verificar arquivo
|
41 |
+
if os.path.exists(output_file):
|
42 |
+
size = os.path.getsize(output_file) / 1024
|
43 |
+
print(f"Arquivo gerado com sucesso\! Tamanho: {size:.1f} KB")
|
44 |
+
else:
|
45 |
+
print("Erro: Arquivo não foi gerado")
|
46 |
+
|
47 |
+
except Exception as e:
|
48 |
+
print(f"Erro: {e}")
|
49 |
+
import traceback
|
50 |
+
traceback.print_exc()
|
test_audio_timed.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#\!/usr/bin/env python3
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
import time
|
5 |
+
import torch
|
6 |
+
import torchaudio
|
7 |
+
import numpy as np
|
8 |
+
|
9 |
+
print("=== Teste de Áudio com Medição de Tempo ===")
|
10 |
+
print()
|
11 |
+
|
12 |
+
# Criar um áudio sintético simples para testar
|
13 |
+
print("Gerando áudio de teste...")
|
14 |
+
start_time = time.time()
|
15 |
+
|
16 |
+
# Parâmetros do áudio
|
17 |
+
sample_rate = 22050
|
18 |
+
duration = 5 # segundos
|
19 |
+
frequency = 440 # Hz (nota Lá)
|
20 |
+
|
21 |
+
# Gerar onda senoidal com envelope
|
22 |
+
t = np.linspace(0, duration, int(sample_rate * duration))
|
23 |
+
# Adicionar envelope para suavizar início e fim
|
24 |
+
envelope = np.ones_like(t)
|
25 |
+
fade_samples = int(0.1 * sample_rate) # 100ms de fade
|
26 |
+
envelope[:fade_samples] = np.linspace(0, 1, fade_samples)
|
27 |
+
envelope[-fade_samples:] = np.linspace(1, 0, fade_samples)
|
28 |
+
|
29 |
+
# Gerar áudio com múltiplas frequências (acorde)
|
30 |
+
audio = np.zeros_like(t)
|
31 |
+
frequencies = [440, 554, 659] # Lá maior
|
32 |
+
for freq in frequencies:
|
33 |
+
audio += 0.2 * np.sin(2 * np.pi * freq * t) * envelope
|
34 |
+
|
35 |
+
# Adicionar um pouco de vibrato
|
36 |
+
vibrato = 0.02 * np.sin(2 * np.pi * 5 * t) # 5Hz vibrato
|
37 |
+
audio = audio * (1 + vibrato)
|
38 |
+
|
39 |
+
# Converter para tensor
|
40 |
+
audio_tensor = torch.FloatTensor(audio).unsqueeze(0)
|
41 |
+
|
42 |
+
# Salvar arquivo
|
43 |
+
output_file = "test_audio_timing.wav"
|
44 |
+
torchaudio.save(output_file, audio_tensor, sample_rate)
|
45 |
+
|
46 |
+
generation_time = time.time() - start_time
|
47 |
+
|
48 |
+
# Estatísticas
|
49 |
+
file_size = os.path.getsize(output_file) / 1024 # KB
|
50 |
+
|
51 |
+
print(f"✅ Áudio gerado com sucesso\!")
|
52 |
+
print()
|
53 |
+
print("📊 Estatísticas:")
|
54 |
+
print(f" - Arquivo: {output_file}")
|
55 |
+
print(f" - Duração: {duration} segundos")
|
56 |
+
print(f" - Taxa de amostragem: {sample_rate} Hz")
|
57 |
+
print(f" - Tamanho: {file_size:.1f} KB")
|
58 |
+
print(f" - Tempo de geração: {generation_time:.3f} segundos")
|
59 |
+
print(f" - Velocidade: {duration/generation_time:.1f}x tempo real")
|
60 |
+
print()
|
61 |
+
print("🎵 Áudio contém um acorde de Lá maior com vibrato")
|
test_tts_simple.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import os
|
3 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
4 |
+
|
5 |
+
# Import direto sem dependências complexas
|
6 |
+
import torch
|
7 |
+
import torchaudio
|
8 |
+
import numpy as np
|
9 |
+
|
10 |
+
print("Teste simples de TTS")
|
11 |
+
print("Gerando áudio de teste...")
|
12 |
+
|
13 |
+
# Criar um áudio de teste simples
|
14 |
+
sample_rate = 16000
|
15 |
+
duration = 3 # segundos
|
16 |
+
frequency = 440 # Hz (nota Lá)
|
17 |
+
|
18 |
+
# Gerar onda senoidal
|
19 |
+
t = np.linspace(0, duration, int(sample_rate * duration))
|
20 |
+
waveform = 0.3 * np.sin(2 * np.pi * frequency * t)
|
21 |
+
|
22 |
+
# Converter para tensor
|
23 |
+
audio_tensor = torch.FloatTensor(waveform).unsqueeze(0)
|
24 |
+
|
25 |
+
# Salvar o áudio
|
26 |
+
output_file = "test_audio_simple.wav"
|
27 |
+
torchaudio.save(output_file, audio_tensor, sample_rate)
|
28 |
+
|
29 |
+
print(f"Áudio salvo em: {output_file}")
|
30 |
+
print(f"Duração: {duration} segundos")
|
31 |
+
print(f"Taxa de amostragem: {sample_rate} Hz")
|