Spaces:
Configuration error
Configuration error
| #!/usr/bin/env python3 | |
| import os | |
| print("=== Estimativa de Treinamento CosyVoice para Português ===\n") | |
| # Verificar GPU disponível | |
| print("1. Verificando Hardware") | |
| print("-" * 50) | |
| try: | |
| import torch | |
| if torch.cuda.is_available(): | |
| gpu_name = torch.cuda.get_device_name(0) | |
| gpu_memory = torch.cuda.get_device_properties(0).total_memory / (1024**3) | |
| print(f"GPU: {gpu_name}") | |
| print(f"Memória: {gpu_memory:.1f} GB") | |
| # Verificar se é uma RTX A5000 | |
| if "A5000" in gpu_name or "RTX A5000" in gpu_name: | |
| print("✓ RTX A5000 detectada - Excelente para treinamento!") | |
| gpu_factor = 1.0 # Baseline | |
| elif "A100" in gpu_name: | |
| print("✓ A100 detectada - Ótima para treinamento!") | |
| gpu_factor = 0.6 # 40% mais rápida | |
| elif "V100" in gpu_name: | |
| print("✓ V100 detectada - Boa para treinamento!") | |
| gpu_factor = 1.3 # 30% mais lenta | |
| else: | |
| gpu_factor = 1.5 # GPUs consumer são mais lentas | |
| else: | |
| print("❌ Sem GPU CUDA disponível") | |
| gpu_factor = 10.0 # CPU seria 10x mais lento | |
| except ImportError: | |
| print("PyTorch não instalado") | |
| gpu_factor = 1.0 | |
| print("\n2. Requisitos de Dados para Fine-tuning") | |
| print("-" * 50) | |
| # Baseado em papers e experiências com modelos TTS | |
| data_requirements = { | |
| "Mínimo (adaptação básica)": { | |
| "horas": 1, | |
| "frases": 500, | |
| "qualidade": "Sotaque melhorado, prosódia básica" | |
| }, | |
| "Recomendado (boa qualidade)": { | |
| "horas": 10, | |
| "frases": 5000, | |
| "qualidade": "Voz natural, boa prosódia" | |
| }, | |
| "Ideal (qualidade comercial)": { | |
| "horas": 50, | |
| "frases": 25000, | |
| "qualidade": "Qualidade profissional, múltiplos falantes" | |
| } | |
| } | |
| for nivel, info in data_requirements.items(): | |
| print(f"\n{nivel}:") | |
| print(f" - Áudio necessário: {info['horas']} hora(s)") | |
| print(f" - Frases aproximadas: {info['frases']:,}") | |
| print(f" - Qualidade esperada: {info['qualidade']}") | |
| print("\n3. Estimativa de Tempo de Treinamento (RTX A5000)") | |
| print("-" * 50) | |
| # Baseado no tamanho do modelo e benchmarks típicos | |
| model_params = { | |
| "CosyVoice-300M": { | |
| "params": 300_000_000, | |
| "batch_size": 16, # RTX A5000 com 24GB consegue batch maior | |
| "steps_per_hour": 100, # steps por hora de áudio | |
| "epochs_needed": 20 | |
| }, | |
| "CosyVoice2-0.5B": { | |
| "params": 500_000_000, | |
| "batch_size": 8, | |
| "steps_per_hour": 150, | |
| "epochs_needed": 15 | |
| } | |
| } | |
| for model_name, params in model_params.items(): | |
| print(f"\n{model_name}:") | |
| for nivel, data in data_requirements.items(): | |
| horas_audio = data['horas'] | |
| total_steps = params['steps_per_hour'] * horas_audio * params['epochs_needed'] | |
| # RTX A5000 faz ~30-50 steps/min para modelos deste tamanho | |
| steps_per_minute = 40 if "300M" in model_name else 30 | |
| training_hours = (total_steps / steps_per_minute / 60) * gpu_factor | |
| print(f" {nivel}: ~{training_hours:.1f} horas ({training_hours/24:.1f} dias)") | |
| print("\n4. Configuração Recomendada para Fine-tuning") | |
| print("-" * 50) | |
| config = """ | |
| # config_finetune_pt.yaml | |
| model: CosyVoice-300M | |
| learning_rate: 1e-4 | |
| batch_size: 16 | |
| gradient_accumulation: 2 | |
| num_epochs: 20 | |
| warmup_steps: 500 | |
| # Dados | |
| audio_sample_rate: 22050 | |
| max_duration: 10.0 # segundos | |
| min_duration: 0.5 # segundos | |
| # Augmentação | |
| speed_perturb: [0.95, 1.0, 1.05] | |
| volume_perturb: [0.9, 1.0, 1.1] | |
| """ | |
| print(config) | |
| print("\n5. Estrutura de Dados Necessária") | |
| print("-" * 50) | |
| estrutura = """ | |
| data/ | |
| ├── portuguese/ | |
| │ ├── train/ | |
| │ │ ├── audio/ | |
| │ │ │ ├── pt_001.wav | |
| │ │ │ ├── pt_002.wav | |
| │ │ │ └── ... | |
| │ │ └── transcripts.txt # formato: filename|text|speaker | |
| │ └── val/ | |
| │ ├── audio/ | |
| │ └── transcripts.txt | |
| """ | |
| print(estrutura) | |
| print("\n6. Processo de Fine-tuning") | |
| print("-" * 50) | |
| steps = """ | |
| 1. Preparar dados: | |
| - Gravar ou obter áudio em português (22.05kHz, mono, 16-bit) | |
| - Transcrever com pontuação correta | |
| - Normalizar texto (números por extenso, etc.) | |
| 2. Preprocessar: | |
| python preprocess.py --config config_finetune_pt.yaml | |
| 3. Treinar: | |
| python train.py --config config_finetune_pt.yaml --gpus 1 | |
| 4. Monitorar: | |
| tensorboard --logdir logs/ | |
| 5. Inferência: | |
| python inference.py --checkpoint best_model.pt --text "Teste" | |
| """ | |
| print(steps) | |
| print("\n7. Alternativas Mais Rápidas") | |
| print("-" * 50) | |
| alternativas = """ | |
| • Voice Cloning (5-30 min de áudio): | |
| - Coqui XTTS v2: Suporta PT-BR nativamente | |
| - Tortoise TTS: Boa qualidade mas lento | |
| • Modelos Pré-treinados PT-BR: | |
| - YourTTS (Coqui): Já tem vozes brasileiras | |
| - Google TTS API: Qualidade comercial | |
| - Azure Neural TTS: Vozes PT-BR naturais | |
| • Serviços de Fine-tuning: | |
| - ElevenLabs: Clone de voz em minutos | |
| - Play.ht: Vozes personalizadas rápido | |
| """ | |
| print(alternativas) | |
| print("\n" + "="*60) | |
| print("RESUMO para RTX A5000:") | |
| print("- Adaptação mínima: 1h áudio, ~5-10h treinamento") | |
| print("- Boa qualidade: 10h áudio, ~2-3 dias treinamento") | |
| print("- Clone de voz: 10-30min áudio, resultado em 1h") | |
| print("="*60) |