51 lines
3.0 KiB
Python
51 lines
3.0 KiB
Python
"""Scoped real CPU worker test with synthetic text; no production request/switch."""
|
|
import argparse,hashlib,json,time,wave
|
|
from pathlib import Path
|
|
import sys
|
|
from types import SimpleNamespace
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[2]))
|
|
from kikiri_runtime import KikiriRuntime,REPO,MODEL_REVISION,MODEL_FILE,MODEL_SHA
|
|
from kikiri import Kikiri
|
|
|
|
def verify(state):
|
|
state=Path(state);root=state/'kikiri-verification-jobs'
|
|
root.mkdir(exist_ok=True,mode=0o700)
|
|
watched=('profiles.json','endpoint.json','audio-policy.json','cpu-partition.json')
|
|
def hashes():return {n:hashlib.sha256((state/n).read_bytes()).hexdigest() for n in watched if (state/n).is_file()}
|
|
before=hashes();runtime=KikiriRuntime(state/'kikiri-runtime');assert runtime.status()['installed']
|
|
model=dict(kind='audio',repo=REPO,revision=MODEL_REVISION,file=MODEL_FILE,sha256=MODEL_SHA)
|
|
row=dict(id='c'*32,revision=1,runnable=True,parameters={'speed':1},model=model)
|
|
worker=Kikiri(root,SimpleNamespace(status=lambda:{'profiles':[row]}),runtime)
|
|
cases={
|
|
'expressive':'Guten Morgen, Michael. Schön, dass du wieder da bist! Draußen rauscht der Regen, und die Vögel suchen Schutz unter dem Dach. Wirklich? Das hätte ich nicht gedacht. Heute nehmen wir uns ein wenig Zeit und machen alles ganz in Ruhe.',
|
|
'technical':'Home Assistant läuft auf Unraid. Der Docker-Container meldet 47 Grad. Im Logfile stehen keine Fehler. Der freie Speicher beträgt 512 MiB. Die Verbindung liefert 100 Mbit pro Sekunde. Um 18:30 CEST beginnt der nächste Scan.'}
|
|
results=[];began=time.monotonic()
|
|
try:
|
|
for case,text in cases.items():
|
|
if case=='technical':
|
|
from tts_text_enhancer import prepare
|
|
text=prepare(text,'German')
|
|
job=worker.start(row['id'],text,streaming=True);deadline=time.monotonic()+150
|
|
while True:
|
|
current=worker.job_status(job['id'])
|
|
if current['state']!='running':break
|
|
if time.monotonic()>deadline:raise RuntimeError('Own worker test timed out')
|
|
time.sleep(.1)
|
|
assert current['state']=='complete',current['phase']
|
|
directory=root/job['id'];pcm=b''.join(p.read_bytes() for p in sorted(directory.glob('chunk-*.pcm')))
|
|
with wave.open(str(directory/'result.wav')) as w:
|
|
assert (w.getframerate(),w.getnchannels(),w.getsampwidth())==(24000,1,2)
|
|
assert w.readframes(w.getnframes())==pcm
|
|
item={k:current[k] for k in ('id','duration','sample_rate','seconds','first_chunk_seconds')}
|
|
item.update(case=case,rtf=current['seconds']/current['duration'],pcm_matches_wav=True)
|
|
results.append(item)
|
|
finally:worker.stop()
|
|
result=dict(complete=len(results)==2,runs=results,wall_seconds=time.monotonic()-began,
|
|
production_config_unchanged=before==hashes(),own_worker_stopped=worker.process is None)
|
|
(root/'verification.json').write_text(json.dumps(result,indent=2)+'\n')
|
|
print(json.dumps(result),flush=True)
|
|
assert result['complete'] and result['production_config_unchanged']
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('--state',required=True,type=Path);a=p.parse_args();verify(a.state)
|