21 lines
1.7 KiB
Python
21 lines
1.7 KiB
Python
"""Run synthetic probes on Helper. Read API key internally, never print it."""
|
|
import io,json,pathlib,time,urllib.request,urllib.error,wave,subprocess
|
|
key=pathlib.Path('/etc/athena-helper-tts/api-key').read_text().strip()
|
|
base='http://172.21.117.203:8099'
|
|
rows=[]
|
|
for path in ('/health','/v1/audio/voices'):
|
|
with urllib.request.urlopen(urllib.request.Request(base+path,headers={'Authorization':'Bearer '+key}),timeout=20) as r: rows.append({'path':path,'status':r.status,'metadata':json.load(r)})
|
|
for path in ('/health','/tts_to_audio'):
|
|
try: urllib.request.urlopen(base+path,timeout=20)
|
|
except urllib.error.HTTPError as e: rows.append({'unauthenticated':path,'status':e.code})
|
|
for fmt in ('wav','mp3'):
|
|
data=json.dumps({'model':'tts-1','voice':'alloy','input':'Hallo Michael. Die Sprachausgabe läuft jetzt auf dem separaten Rechner. Athena bleibt dabei unverändert.','response_format':fmt}).encode()
|
|
s=time.monotonic()
|
|
with urllib.request.urlopen(urllib.request.Request(base+'/v1/audio/speech',data=data,headers={'Content-Type':'application/json','Authorization':'Bearer '+key}),timeout=90) as r:
|
|
audio=r.read();ctype=r.headers.get('Content-Type')
|
|
elapsed=time.monotonic()-s
|
|
target=pathlib.Path('/opt/athena-helper-tts')/('api-test.'+fmt);target.write_bytes(audio)
|
|
duration=float(subprocess.check_output(['/usr/bin/ffprobe','-v','error','-show_entries','format=duration','-of','default=noprint_wrappers=1:nokey=1',str(target)]))
|
|
rows.append({'format':fmt,'content_type':ctype,'elapsed_seconds':round(elapsed,3),'audio_seconds':duration,'rtf':round(elapsed/duration,3),'bytes':len(audio)})
|
|
pathlib.Path('/opt/athena-helper-tts/api-measurements.json').write_text(json.dumps(rows,indent=2));print(json.dumps(rows,indent=2))
|