File size: 1,886 Bytes
93f5fa9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Test the API locally before deploying

import requests
import sys

def test_api(base_url="http://localhost:7860"):
    print("🧪 Testing AI Voice Enhancer API\n")
    print(f"Base URL: {base_url}\n")
    
    # Test 1: Root endpoint
    print("1️⃣ Testing GET / ...")
    try:
        response = requests.get(f"{base_url}/")
        print(f"   Status: {response.status_code}")
        print(f"   Response: {response.json()}\n")
    except Exception as e:
        print(f"   ❌ Error: {e}\n")
        return False
    
    # Test 2: Health check
    print("2️⃣ Testing GET /health ...")
    try:
        response = requests.get(f"{base_url}/health")
        print(f"   Status: {response.status_code}")
        print(f"   Response: {response.json()}\n")
    except Exception as e:
        print(f"   ❌ Error: {e}\n")
        return False
    
    # Test 3: Enhancement endpoint (without file)
    print("3️⃣ Testing POST /enhance (validation) ...")
    try:
        response = requests.post(f"{base_url}/enhance")
        print(f"   Status: {response.status_code}")
        if response.status_code == 422:
            print(f"   ✅ Validation working correctly\n")
        else:
            print(f"   Response: {response.text}\n")
    except Exception as e:
        print(f"   ❌ Error: {e}\n")
    
    print("✅ All basic tests passed!")
    print("\n📝 To test audio enhancement:")
    print("   1. Run: python api.py")
    print("   2. Upload a test audio file via frontend")
    print("   OR use:")
    print(f'   curl -X POST "{base_url}/enhance" -F "file=@test.wav" -F "speech_level=80" -F "background_level=85" -o output.wav')
    
    return True

if __name__ == "__main__":
    # Check if custom URL provided
    url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:7860"
    test_api(url)