vad_demo / quick_fix.py
Gabriel Bibbó
🎤 VAD Demo - Complete Implementation
552ebb8
#!/usr/bin/env python3
"""
Quick test script to verify everything works before full demo
"""
import numpy as np
import gradio as gr
print("🧪 Testing core libraries...")
try:
import torch
print("✅ PyTorch:", torch.__version__)
except ImportError as e:
print("❌ PyTorch:", e)
try:
import librosa
print("✅ Librosa:", librosa.__version__ if hasattr(librosa, '__version__') else "OK")
# Test librosa functionality
y = np.random.randn(1000).astype(np.float32)
mfcc = librosa.feature.mfcc(y=y, sr=16000, n_mfcc=1)
stft = librosa.stft(y)
print("✅ Librosa functions working")
except ImportError as e:
print("❌ Librosa import:", e)
except Exception as e:
print("❌ Librosa functions:", e)
try:
import numba
print("✅ Numba:", numba.__version__)
except ImportError as e:
print("❌ Numba:", e)
print("\n🎤 Testing Silero-VAD...")
try:
model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad',
model='silero_vad',
force_reload=False)
# Test with correct chunk size
test_audio = torch.randn(1, 512) # Correct size for 16kHz
with torch.no_grad():
result = model(test_audio, 16000)
print(f"✅ Silero-VAD working: {result.item():.3f}")
except Exception as e:
print(f"❌ Silero-VAD error: {e}")
print("\n🎨 Testing Gradio...")
try:
def dummy_function(audio):
if audio is not None:
return "Audio received!", np.random.random()
return "No audio", 0.0
interface = gr.Interface(
fn=dummy_function,
inputs=gr.Audio(sources=["microphone"], type="numpy"),
outputs=[gr.Textbox(), gr.Number()],
title="Quick Test"
)
print("✅ Gradio interface created")
# Launch for quick test
print("\n🚀 Launching test interface on http://127.0.0.1:7860")
print(" Test microphone, then close and run full demo")
interface.launch(
server_name="127.0.0.1",
server_port=7860,
show_error=True,
quiet=False
)
except Exception as e:
print(f"❌ Gradio error: {e}")
print("\n🎯 If everything above shows ✅, run: python app.py")