"""Check available clips against source audio and run an independent ASR screen. ASR similarity is a triage aid, not a pronunciation or visual lip-sync verdict. """ from pathlib import Path import difflib import json import re import subprocess import sys import numpy as np from scipy.signal import correlate, correlation_lags ROOT=Path(__file__).resolve().parents[3] sys.path.insert(0,str(ROOT/'ai_person/ai_person_api')) from app.config import get_settings from app.services.asr_service import AsrService REPORT=ROOT/'unreal_tran/ute2e/reports/bridge-narration-junhao-20260921' WEB=ROOT/'unreal_tran/unreal_tran_web/public' def pcm(settings,path): return np.frombuffer(subprocess.run([settings.ffmpeg_binary,'-v','error','-i',str(path), '-vn','-ac','1','-ar','16000','-f','f32le','pipe:1'],capture_output=True,check=True).stdout,dtype=np.float32) def normalize(text): numbers=['零','一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五','十六'] text=re.sub(r'\d+',lambda m:numbers[int(m[0])] if int(m[0]).9 and abs(len(a)-len(b))<16000*.7, 'needsTranscriptReview':similarity<.85} results=[r for r in results if r['key']!=clip['key']]+[row] temp=target.with_suffix('.tmp');temp.write_text(json.dumps(results,ensure_ascii=False,indent=2),'utf-8');temp.replace(target) print(clip['key'],row['technicalPass'],'ASR',row['asrSimilarity'],'lag',row['audioLagMs'],flush=True) if __name__=='__main__':main()