check_service.py 1.4 KB

12345678910111213141516171819202122232425262728
  1. """À exécuter depuis le pod Satoko ; aucun appel à Discord."""
  2. import io
  3. import json
  4. import time
  5. import wave
  6. import httpx
  7. with httpx.Client(timeout=90) as http:
  8. health = http.get('http://kokoro-tts:8000/healthz')
  9. health.raise_for_status()
  10. print(health.json())
  11. for text in (
  12. 'Bonjour, je suis prête à discuter avec vous.',
  13. 'Tu peux maintenant me parler dans le salon vocal, et je te répondrai directement à voix haute.',
  14. 'Les trois serveurs fonctionnent correctement. Nous pouvons continuer notre partie tranquillement.',
  15. ):
  16. started = time.monotonic()
  17. response = http.post('http://kokoro-tts:8000/v1/audio/speech', json={'input': text, 'voice': 'ff_siwis'})
  18. response.raise_for_status()
  19. with wave.open(io.BytesIO(response.content)) as wav:
  20. assert wav.getframerate() == 24000 and wav.getnchannels() == 1 and wav.getsampwidth() == 2
  21. duration = wav.getnframes() / wav.getframerate()
  22. print(json.dumps({'characters': len(text), 'request_seconds': round(time.monotonic()-started, 3),
  23. 'generation_seconds': response.headers.get('X-Generation-Seconds'),
  24. 'audio_seconds': round(duration, 3)}, ensure_ascii=False))
  25. invalid = http.post('http://kokoro-tts:8000/v1/audio/speech', json={'input': 'bonjour', 'voice': '../unknown'})
  26. assert invalid.status_code == 422
  27. print('WAV et validation de voix : OK')