Files
game_voice_recorder/app/scripts/stt-eval.mts
EJClaw 5f04ccdd4e M5: 포터블 exe 앱 (트레이·설정 창·첫 실행 마법사) + M6 사전 기능
- app/src/main: Electron 메인(트레이 상태 아이콘, 설정 창, 단일 실행, DPAPI safeStorage, 스모크 모드), IPC(window.gvr), 파인튜닝 관리
- app/src/renderer: 설정 8개 탭 + 5단계 첫 실행 마법사 (React)
- electron-builder: GameVoiceRecorder.exe, zip(폴더 포터블) + 단일 exe 포터블, 워커·리소스 포함
- 사전: 사이트에서 단어·교정 규칙 추가/삭제(/api/dictionary), 게임 패치 이름 자동 추가, 묶음별 중복 허용 + DB 마이그레이션
- 사이트 서버: 종료 시 WebSocket 먼저 끊기(재시작 멈춤 수정) + 재연결 테스트
- scripts/finetune-e2e.mts, stt-eval.mts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 02:16:08 +09:00

70 lines
3.6 KiB
TypeScript

// M7 인식률 평가: 시연 대화 28문장(TTS)을 모델별로 변환해 CER(글자 오류율)을 잰다. 사전(핫워드+교정) 있음/없음 비교.
// node --import tsx scripts/stt-eval.mts <models_dir> <model...>
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { Store } from '../src/core/db/db.ts';
import { Dictionary } from '../src/core/dict/dictionary.ts';
import { WorkerClient } from '../src/core/stt/worker.ts';
const [modelsDir, ...models] = process.argv.slice(2);
const root = path.resolve(import.meta.dirname, '..', '..');
const clipDir = path.join(os.homedir(), '.tmp', 'gvr-demo-clips');
const demo = fs.readFileSync(path.join(import.meta.dirname, 'demo-stack.mts'), 'utf8');
const lines = [...demo.matchAll(/\{ u: \d, text: '([^']+)', at: \{ (val|lol|off)/g)].map((m) => ({ text: m[1], ctx: m[2] === 'val' ? 'valorant' : m[2] === 'lol' ? 'lol' : 'none' })) as { text: string; ctx: 'valorant' | 'lol' | 'none' }[];
const norm = (s: string) => s.replace(/[\s.,!?~]/g, '').replace(/PC방/g, '피시방').replace(/2명/g, '두명');
function cer(ref: string, hyp: string): number {
const a = [...norm(ref)];
const b = [...norm(hyp)];
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...new Array(b.length).fill(0)]);
for (let j = 1; j <= b.length; j++) d[0][j] = j;
for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
return d[a.length][b.length] / Math.max(1, a.length);
}
const tmp = fs.mkdtempSync(path.join(os.homedir(), '.tmp', 'gvr-eval-'));
const store = new Store(path.join(tmp, 'db.sqlite'));
const dict = new Dictionary(store, path.join(root, 'app', 'resources'), () => ({}));
dict.seed();
const w = new WorkerClient({ cmd: path.join(root, 'worker/.venv/bin/python'), args: ['-m', 'gvr_worker'], cwd: path.join(root, 'worker'), env: { GVR_DATA_DIR: tmp, GVR_MODELS_DIR: modelsDir, GVR_LOG_LEVEL: 'WARNING' } });
w.start();
await new Promise((r) => w.once('ready', r));
const report: string[] = [];
for (const model of models) {
const t0 = Date.now();
await w.request('load', { slot: 'realtime', model, device: 'cpu', compute_type: 'int8' }, 30 * 60000);
const loadS = (Date.now() - t0) / 1000;
for (const useDict of [false, true]) {
let sum = 0;
let exact = 0;
let ms = 0;
const rows: string[] = [];
for (const [i, l] of lines.entries()) {
const r = await w.request('transcribe', {
slot: 'realtime',
path: path.join(clipDir, `${i}.ogg`),
hotwords: useDict ? dict.hotwords(l.ctx) : '',
corrections: useDict ? dict.corrections() : [],
dictionary: useDict ? dict.candidates(l.ctx) : [],
target_lufs: -18,
noise_sensitivity: 0.5,
denoise: false,
profile_lufs: null,
}, 10 * 60000);
const hyp = r.text ?? '';
const c = cer(l.text, hyp);
sum += c;
if (c === 0) exact++;
ms += r.elapsed_ms;
rows.push(` ${c === 0 ? '=' : c < 0.15 ? '≈' : '≠'} ${l.text} → ${hyp}`);
}
const line = `${model} ${useDict ? '사전 적용' : '사전 없음'}: CER ${((sum / lines.length) * 100).toFixed(1)}% · 완전 일치 ${exact}/${lines.length} · 평균 ${(ms / lines.length / 1000).toFixed(2)}초/문장 (CPU int8) · 적재 ${loadS.toFixed(0)}초`;
console.log(line);
if (useDict) console.log(rows.join('\n'));
report.push(line);
}
await w.request('unload', { slot: 'realtime' });
}
console.log('\n== 요약 ==\n' + report.join('\n'));
await w.stop();
process.exit(0);