File size: 3,175 Bytes
de63014
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
"""
Script de test pour diagnostiquer le problème WebSocket
"""

import asyncio
import aiohttp
import json
import sys

async def test_services():
    """Teste tous les services backend"""
    print("🔍 Test des services backend...")
    
    services = [
        ("TTS", "http://localhost:5000/health"),
        ("STT", "http://localhost:5001/health"),
        ("LLM", "http://localhost:5002/health"),
        ("Live Stream", "http://localhost:5003/health"),
    ]
    
    for name, url in services:
        try:
            async with aiohttp.ClientSession() as session:
                async with session.get(url) as resp:
                    if resp.status == 200:
                        print(f"✅ {name}: OK")
                    else:
                        print(f"❌ {name}: Erreur (status {resp.status})")
        except Exception as e:
            print(f"❌ {name}: Erreur de connexion - {e}")

async def test_tts():
    """Teste le service TTS"""
    print("\n🧪 Test TTS...")
    try:
        async with aiohttp.ClientSession() as session:
            data = {"text": "Test", "lang": "fr"}
            async with session.post("http://localhost:5000/generate-tts", json=data) as resp:
                if resp.status == 200:
                    result = await resp.json()
                    print(f"✅ TTS: OK - {result}")
                else:
                    print(f"❌ TTS: Erreur (status {resp.status})")
    except Exception as e:
        print(f"❌ TTS: Erreur - {e}")

async def test_stt():
    """Teste le service STT"""
    print("\n🧪 Test STT...")
    try:
        # Créer un fichier audio de test simple
        import wave
        import tempfile
        
        with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
            # Créer un fichier WAV de 1 seconde de silence
            with wave.open(f.name, 'w') as wav_file:
                wav_file.setnchannels(1)
                wav_file.setsampwidth(2)
                wav_file.setframerate(16000)
                wav_file.writeframes(b'\x00' * 32000)  # 1 seconde de silence
            
            async with aiohttp.ClientSession() as session:
                with open(f.name, 'rb') as audio_file:
                    data = aiohttp.FormData()
                    data.add_field('audio', audio_file, filename='test.wav', content_type='audio/wav')
                    data.add_field('language', 'fr')
                    
                    async with session.post("http://localhost:5001/transcribe", data=data) as resp:
                        if resp.status == 200:
                            result = await resp.json()
                            print(f"✅ STT: OK - {result}")
                        else:
                            print(f"❌ STT: Erreur (status {resp.status})")
        
        import os
        os.unlink(f.name)
    except Exception as e:
        print(f"❌ STT: Erreur - {e}")

async def main():
    print("🚀 Démarrage des tests...")
    await test_services()
    await test_tts()
    await test_stt()
    print("\n✅ Tests terminés")

if __name__ == "__main__":
    asyncio.run(main())