"""Export real Smart Turn scores across complete recordings for EOT Studio.""" import csv import hashlib import json import numpy as np import soundfile as sf from loguru import logger from pipecat.audio.turn.smart_turn.local_smart_turn_v3 import LocalSmartTurnAnalyzerV3 from evaluate_can_reply import HERE, ROOT, block_origin def read(p): with p.open(encoding='utf-8-sig') as f: return list(csv.DictReader(f)) def main(): logger.remove() checkpoints = read(HERE/'results/work-data-can-reply/predictions.csv') history = read(ROOT/'labels/EOT标注/工作数据/asr_history.csv') events = read(HERE/'results/work-data-pipecat/events.csv') weight = HERE/'smart-turn-v3.2-cpu.onnx' analyzer = LocalSmartTurnAnalyzerV3(smart_turn_model_path=str(weight),cpu_count=4) calls=[] for call in sorted({r['call_id'] for r in checkpoints}): path=ROOT/'data/韩泰机器人抢话/音频'/f'{call}.mp3' pcm,sr=sf.read(path,dtype='int16',always_2d=True) duration=round(len(pcm)*1000/sr,3) call_labels=[r for r in checkpoints if r['call_id']==call] exact={int(r['decision_ms']):float(r['probability']) for r in call_labels} times=sorted(set(range(200,int(duration)+1,200))|set(exact)|{int(duration)}) call_history=[r for r in history if r['call_id']==call] starts=sorted(float(e['event_ms']) for e in events if e['call_id']==call and e['event']=='vad_start') analyzer.set_sample_rate(sr) points=[] for decision in times: origin=block_origin(call_history,decision) if origin is None: past=[t for t in starts if t<=decision] origin=max(0,past[-1]+32-200-500) if past else 0 end=decision*sr//1000 start=max(round(origin*sr/1000),end-sr*8) assert 0<=start