Avatar / test_websocket.py
DataSage12's picture
Initial commit - HOLOKIA-AVATAR v2.2
de63014
#!/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())