Spaces:
Configuration error
Configuration error
| #\!/usr/bin/env python3 | |
| import os | |
| import sys | |
| import time | |
| import torch | |
| import torchaudio | |
| import numpy as np | |
| print("=== Teste de Áudio com Medição de Tempo ===") | |
| print() | |
| # Criar um áudio sintético simples para testar | |
| print("Gerando áudio de teste...") | |
| start_time = time.time() | |
| # Parâmetros do áudio | |
| sample_rate = 22050 | |
| duration = 5 # segundos | |
| frequency = 440 # Hz (nota Lá) | |
| # Gerar onda senoidal com envelope | |
| t = np.linspace(0, duration, int(sample_rate * duration)) | |
| # Adicionar envelope para suavizar início e fim | |
| envelope = np.ones_like(t) | |
| fade_samples = int(0.1 * sample_rate) # 100ms de fade | |
| envelope[:fade_samples] = np.linspace(0, 1, fade_samples) | |
| envelope[-fade_samples:] = np.linspace(1, 0, fade_samples) | |
| # Gerar áudio com múltiplas frequências (acorde) | |
| audio = np.zeros_like(t) | |
| frequencies = [440, 554, 659] # Lá maior | |
| for freq in frequencies: | |
| audio += 0.2 * np.sin(2 * np.pi * freq * t) * envelope | |
| # Adicionar um pouco de vibrato | |
| vibrato = 0.02 * np.sin(2 * np.pi * 5 * t) # 5Hz vibrato | |
| audio = audio * (1 + vibrato) | |
| # Converter para tensor | |
| audio_tensor = torch.FloatTensor(audio).unsqueeze(0) | |
| # Salvar arquivo | |
| output_file = "test_audio_timing.wav" | |
| torchaudio.save(output_file, audio_tensor, sample_rate) | |
| generation_time = time.time() - start_time | |
| # Estatísticas | |
| file_size = os.path.getsize(output_file) / 1024 # KB | |
| print(f"✅ Áudio gerado com sucesso\!") | |
| print() | |
| print("📊 Estatísticas:") | |
| print(f" - Arquivo: {output_file}") | |
| print(f" - Duração: {duration} segundos") | |
| print(f" - Taxa de amostragem: {sample_rate} Hz") | |
| print(f" - Tamanho: {file_size:.1f} KB") | |
| print(f" - Tempo de geração: {generation_time:.3f} segundos") | |
| print(f" - Velocidade: {duration/generation_time:.1f}x tempo real") | |
| print() | |
| print("🎵 Áudio contém um acorde de Lá maior com vibrato") | |