first commit
This commit is contained in:
62
test_http.py
Normal file
62
test_http.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""REST test for Qwen3-TTS /v1/audio/speech endpoint."""
|
||||
import sys
|
||||
import time
|
||||
import requests
|
||||
|
||||
BASE_URL = "http://localhost:8091"
|
||||
OUTPUT_FILE = "test_output.wav"
|
||||
|
||||
|
||||
def check_health():
|
||||
try:
|
||||
r = requests.get(f"{BASE_URL}/health", timeout=5)
|
||||
r.raise_for_status()
|
||||
body = r.json() if r.content else "(leer)"
|
||||
print(f"[OK] /health → HTTP {r.status_code} {body}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"[FAIL] /health: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def test_tts(text: str, voice: str = "Ryan", language: str = "German"):
|
||||
payload = {
|
||||
"model": "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice",
|
||||
"input": text,
|
||||
"voice": voice,
|
||||
"language": language,
|
||||
"response_format": "wav",
|
||||
}
|
||||
print(f"\n[→] POST /v1/audio/speech")
|
||||
print(f" text: {text!r}")
|
||||
print(f" voice: {voice}, language: {language}")
|
||||
|
||||
t0 = time.perf_counter()
|
||||
r = requests.post(f"{BASE_URL}/v1/audio/speech", json=payload, timeout=60)
|
||||
elapsed = time.perf_counter() - t0
|
||||
|
||||
if r.status_code != 200:
|
||||
print(f"[FAIL] HTTP {r.status_code}: {r.text[:300]}")
|
||||
sys.exit(1)
|
||||
|
||||
with open(OUTPUT_FILE, "wb") as f:
|
||||
f.write(r.content)
|
||||
|
||||
kb = len(r.content) / 1024
|
||||
print(f"[OK] {elapsed:.2f}s → {kb:.1f} KB WAV saved to {OUTPUT_FILE}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Testing Qwen3-TTS at {BASE_URL}\n")
|
||||
|
||||
if not check_health():
|
||||
sys.exit(1)
|
||||
|
||||
test_tts(
|
||||
text="Hallo! Ich bin ein KI-Sprachassistent. Wie kann ich Ihnen helfen?",
|
||||
voice="Ryan",
|
||||
language="German",
|
||||
)
|
||||
|
||||
print("\nAll tests passed.")
|
||||
Reference in New Issue
Block a user