Files
game_voice_recorder/app/test/e2e-stt.test.ts
EJClaw 7c9146cd2d M0: 기술 검증 - 구조 설계, STT 워커, 앱 코어, 게임 PC 진단
- docs/dev/ARCHITECTURE.md: 코어-워커-사이트 인터페이스 계약
- worker/: faster-whisper 한국어 STT, 음량 정규화, 4단계 잡음 판정, 사전 교정, GPU 감지·모델/CUDA 다운로드, 롤 채팅 OCR·r3dlog, 파인튜닝 파이프라인 (39 tests)
- app/src/core: 디스코드 DAVE 음성 녹음(Ogg Opus), STT 대기열, 발로란트/롤 로컬 API 어댑터, 타임라인·기록 API, 사이트 중계, 7일 음성 삭제, 진단
- tools/gen-dictionary.mjs: 공식 게임 데이터 기반 기본 단어사전 (1993단어)
- M0 결과: DAVE 연결 1.06s Ready, CPU tiny STT 3.6s→0.31s, 가짜 Riot 서버 통합 테스트 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 01:17:48 +09:00

85 lines
4.5 KiB
TypeScript

// 실제 STT 워커(CPU, tiny)와 코어를 붙여 "발화 저장 → 대기열 → STT → DB → 실시간 이벤트 → API" 를 확인한다.
// 워커 venv(worker/.venv)와 HF 캐시의 tiny 모델이 있어야 한다. 없으면 건너뛴다.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
const root = path.resolve(import.meta.dirname, '..', '..');
const py = path.join(root, 'worker', '.venv', 'bin', 'python');
const hfTiny = path.join(os.homedir(), '.cache/huggingface/hub/models--Systran--faster-whisper-tiny/snapshots');
const skip = !fs.existsSync(py) || !fs.existsSync(hfTiny);
test('E2E: 발화 → STT 워커 → DB → 실시간 이벤트 → 기록 API', { skip, timeout: 180000 }, async () => {
const { startCore } = await import('../src/core/index.ts');
const dataDir = fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'gvr-e2e-'));
const models = path.join(dataDir, 'models');
fs.mkdirSync(models, { recursive: true });
fs.symlinkSync(path.join(hfTiny, fs.readdirSync(hfTiny)[0]), path.join(models, 'tiny'));
fs.writeFileSync(
path.join(dataDir, 'settings.json'),
JSON.stringify({ stt: { realtimeModel: 'tiny', preciseModel: 'tiny', device: 'cpu', computeType: 'int8' }, games: { valorant: false, lol: false } }),
);
const core = await startCore({
dataDir,
resourcesDir: path.join(root, 'app', 'resources'),
worker: { cmd: py, args: ['-m', 'gvr_worker'], cwd: path.join(root, 'worker') },
version: 'test',
});
const live: any[] = [];
core.bus.on('live', (e) => live.push(e));
try {
const wait = async (fn: () => boolean, ms: number, label: string) => {
const t = Date.now();
while (!fn()) {
if (Date.now() - t > ms) throw new Error(`timeout ${label}: ${JSON.stringify(core.stt.status)}`);
await new Promise((r) => setTimeout(r, 100));
}
};
await wait(() => core.stt.status.slots.realtime.state === 'loaded', 60000, 'model load');
core.store.upsertUser({ id: 'u1', name: '승한', avatar: null });
const fx = path.join(root, 'worker', 'tests', 'fixtures');
const items: [string, string][] = [
['speech', 'speech_ko.ogg'],
['quiet', 'speech_ko_quiet.ogg'],
['keys', 'keyboard_clicks.ogg'],
];
const t0 = Date.now();
for (const [id, f] of items) {
const dst = path.join(core.paths().audio, 'test', `${id}.ogg`);
fs.mkdirSync(path.dirname(dst), { recursive: true });
fs.copyFileSync(path.join(fx, f), dst);
core.store.insertUtterance({ id, session_id: null, user_id: 'u1', started_at: t0, ended_at: t0 + 3000, audio_path: dst, match_id: null });
core.stt.enqueue(id, 'realtime');
}
await wait(() => items.every(([id]) => core.store.getUtterance(id)!.status !== 'pending'), 120000, 'transcribe');
const sp = core.store.getUtterance('speech')!;
console.log('speech →', sp.text, '| raw:', sp.raw_text, '| gain', sp.gain_db);
assert.ok(['realtime', 'precise'].includes(sp.status), sp.status);
assert.ok(sp.text && sp.text.includes('레이즈'), sp.text ?? '');
assert.ok(JSON.parse(sp.words).length >= 3);
const q = core.store.getUtterance('quiet')!;
assert.ok(q.gain_db > 15, `quiet gain ${q.gain_db}`);
const k = core.store.getUtterance('keys')!;
assert.equal(k.noise, 1);
assert.ok(live.filter((e) => e.type === 'utterance.updated').length >= 3);
// 기록 API (사이트가 중계로 부르는 것과 같은 경로)
const res = await core.api.inject({ method: 'GET', url: '/api/timeline?limit=10' });
const page = res.json();
assert.equal(page.items.length, 3);
const audio = await core.api.inject({ method: 'GET', url: '/api/audio/speech', headers: { range: 'bytes=0-99' } });
assert.equal(audio.statusCode, 206);
assert.equal(audio.rawPayload.length, 100);
// 사이트 교정 → 사전·학습 데이터
const patched = await core.api.inject({ method: 'PATCH', url: '/api/utterances/speech', payload: { text: '레이즈 궁 빠졌어 B 사이트 로테 하자' } });
assert.equal(patched.json().corrected, true);
assert.equal(core.store.trainingSamples().length, 1);
assert.ok(fs.existsSync(core.store.trainingSamples()[0].audio_path));
const search = (await core.api.inject({ method: 'GET', url: '/api/timeline?q=' + encodeURIComponent('B 사이트') })).json();
assert.deepEqual(search.items.map((i: any) => i.id), ['speech']);
} finally {
await core.stop();
}
});