#!/usr/bin/env python
"""
Test script for AudioGen MCP Server
Run this to verify your installation is working correctly.
"""
import asyncio
import sys
async def test_installation():
"""Test that all dependencies are installed correctly."""
print("π Testing AudioGen MCP Installation")
print("=" * 40)
errors = []
# Test PyTorch
print("\n1. Testing PyTorch...")
try:
import torch
print(f" β
PyTorch {torch.__version__}")
print(f" β
MPS available: {torch.backends.mps.is_available()}")
if not torch.backends.mps.is_available():
print(" β οΈ MPS not available - will use CPU (slower)")
except ImportError as e:
print(f" β PyTorch not installed: {e}")
errors.append("torch")
# Test torchaudio
print("\n2. Testing torchaudio...")
try:
import torchaudio
print(f" β
torchaudio {torchaudio.__version__}")
except ImportError as e:
print(f" β torchaudio not installed: {e}")
errors.append("torchaudio")
# Test MCP
print("\n3. Testing MCP SDK...")
try:
import mcp
print(f" β
MCP SDK installed")
except ImportError as e:
print(f" β MCP not installed: {e}")
errors.append("mcp")
# Test AudioCraft
print("\n4. Testing AudioCraft...")
try:
from audiocraft.models import AudioGen
print(f" β
AudioCraft installed")
except ImportError as e:
print(f" β AudioCraft not installed: {e}")
errors.append("audiocraft")
# Test our server module
print("\n5. Testing audiogen_mcp module...")
try:
from audiogen_mcp.server import server, get_device
print(f" β
audiogen_mcp module OK")
print(f" β
Selected device: {get_device()}")
except ImportError as e:
print(f" β audiogen_mcp module error: {e}")
errors.append("audiogen_mcp")
# Summary
print("\n" + "=" * 40)
if errors:
print(f"β {len(errors)} error(s) found. Missing: {', '.join(errors)}")
print("\nRun: pip install -e . ")
return False
else:
print("β
All tests passed!")
print("\nYou can now run the MCP server:")
print(" audiogen-mcp")
return True
async def test_generation():
"""Optional: Test actual audio generation (takes ~60s)."""
print("\nπ΅ Testing Audio Generation (this takes ~60 seconds)...")
print("=" * 40)
try:
from audiogen_mcp.server import generate_sound_effect
result = await generate_sound_effect(
prompt="short beep, electronic, test tone",
duration=2.0
)
if result["success"]:
print(f"β
Generated: {result['filename']}")
print(f" Duration: {result['duration_actual']:.2f}s")
print(f" Generation time: {result['generation_time_seconds']:.1f}s")
print(f" Saved to: {result['file_path']}")
return True
else:
print(f"β Generation failed: {result.get('error')}")
return False
except Exception as e:
print(f"β Error: {e}")
return False
if __name__ == "__main__":
# Always run installation test
success = asyncio.run(test_installation())
# Optionally run generation test
if success and "--generate" in sys.argv:
asyncio.run(test_generation())
elif success:
print("\nTo test audio generation, run:")
print(" python test_installation.py --generate")