Files

37 lines
1.6 KiB
Python

"""Local existing CPU ASR on synthetic Sopro output; no production STT changes."""
from pathlib import Path
import json
import re
import subprocess
import time
ROOT=Path('/data/athena-sopro-cpu-20261027')
BASE=Path('/opt/athena-deck-dev/runtime/state/parakeet-runtime/v0.6.1')
CLI=BASE/'runtime/parakeet-v0.6.1-bin-linux-cpu-x64/parakeet-cli'
def edits(a,b):
prev=list(range(len(b)+1))
for i,x in enumerate(a,1):
row=[i]
for j,y in enumerate(b,1): row.append(min(row[-1]+1,prev[j]+1,prev[j-1]+(x!=y)))
prev=row
return prev[-1]
rows=[]
for results in sorted(ROOT.glob('quality-*.json')):
data=json.loads(results.read_text())
assert data['phase']=='complete'
for run in data['runs']:
start=time.monotonic()
p=subprocess.run([str(CLI),'transcribe','--model',str(BASE/'redux-packed.gguf'),
'--input',str(ROOT/'outputs'/run['file']),'--lang','de','--threads','2','--json'],
capture_output=True,text=True,timeout=90)
row=dict(file=run['file'],case=run['case'],label=run['label'],exit_code=p.returncode,seconds=time.monotonic()-start)
if p.returncode==0:
actual=json.loads(p.stdout)['text'];a=re.findall(r'\w+',run['text'].casefold());b=re.findall(r'\w+',actual.casefold())
row.update(expected=run['text'],recognized=actual,reference_words=len(a),word_edits=edits(a,b),exact_word_match=a==b)
else: row['error']=p.stderr[-1000:]
rows.append(row)
(ROOT/'transcriptions.json').write_text(json.dumps(rows,indent=2,ensure_ascii=False))
print(json.dumps(row,ensure_ascii=False),flush=True)