Files
game_voice_recorder/app/test/e2e-stt.test.ts
EJClaw fa6126e17f v1.3.6: 목소리 깨짐(RTP 기준 쉼 채우기) · 알 수 없음 · 잡음 숨기기/삭제 · 사이트 로그 · 지금 게임 · TTS 속도 · 시작 창
- 녹음기: 패킷 도착 간격 대신 RTP 타임스탬프로 자리를 정한다. 게임 중 몰려 온 패킷 사이에 무음이 끼어 목소리가 깨졌다. 예전 녹음은 한 번 고친 뒤 다시 변환
- users.updated 를 빈 목록으로 보내 사이트에서 말한 사람이 '알 수 없음'이 되던 것
- 잡음은 숨기고 ogg 삭제, 로그에 잡음으로 남김. 짧은 목소리도 Whisper 로, 반복 고리는 줄여서 보여 줌
- 사이트: 재생 음량, 발화 우클릭(자세한 정보 · ogg 다운로드), 사이트 로그(/logs, 게임 PC 꺼져도), 지금 게임 상태
- 앱: 지금 게임 상태, 녹음 안내 말 속도 0.1~2.0, 포터블 · 앱 시작 창
- 발로란트 데스매치 가짜 라운드 · 에이스, 빈 선수 이름

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 05:01:14 +09:00

96 lines
5.2 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.equal(k.audio_deleted, 1);
assert.ok(!fs.existsSync(k.audio_path!));
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.deepEqual(page.items.map((i: any) => i.id).sort(), ['quiet', 'speech']);
// 우클릭 → 자세한 정보: 원본 ogg 이름 · 경로
const info = (await core.api.inject({ method: 'GET', url: '/api/utterances/speech/info' })).json();
assert.equal(info.fileName, 'speech.ogg');
assert.equal(info.path, sp.audio_path);
assert.equal(info.folder, path.dirname(sp.audio_path!));
assert.ok(info.sizeBytes > 1000);
assert.equal(info.deleted, null);
assert.equal((await core.api.inject({ method: 'GET', url: '/api/utterances/keys/info' })).json().deleted, 'noise');
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('궁 빠졌어') })).json();
assert.deepEqual(search.items.map((i: any) => i.id), ['speech']);
} finally {
await core.stop();
}
});