// v1.4.3: 상대 닉네임("QQQWWWQQQ")을 핫워드로 넣었더니 말소리를 "QQQWWWQ" 로 적던 문제 import { test } from 'node:test'; import assert from 'node:assert/strict'; import { EventEmitter } from 'node:events'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { Store } from '../src/core/db/db.ts'; import { Timeline } from '../src/core/timeline.ts'; import { Bus } from '../src/core/util/events.ts'; import { SttPipeline, isNameEcho } from '../src/core/stt/pipeline.ts'; const NAMES = ['QQQWWWQQQ', '노곤노곤탐방가', '하늘 별']; test('선수 이름 되풀이 판정: 이름(조각)만 있으면 되풀이, 실제 말이 붙으면 아님 (워커 is_name_echo 와 같은 기준)', () => { for (const t of ['QQQWWWQ', ' QQQWWWQ.', 'qqqwwwqqq', 'QQQWWWQ QQQWWWQ', '노곤노곤탐방가', '하늘 별']) assert.ok(isNameEcho(t, NAMES), t); for (const t of ['QQQ 잡았다', '노곤노곤탐방가 죽였어', '아이고, 점프티... 아, 갔다.', 'Q', '', null]) assert.ok(!isNameEcho(t, NAMES), String(t)); assert.ok(!isNameEcho('QQQWWWQ', [])); }); function setup() { const dir = fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'gvr-echo-')); const store = new Store(path.join(dir, 'db.sqlite')); store.upsertUser({ id: 'u1', name: '안정우', avatar: null }); const players = [ { name: 'QQQWWWQQQ', character: { name: '제트' } }, { name: '노곤노곤탐방가', character: { name: '레이즈' } }, { name: 'Sky', character: { name: '세이지' } }, ]; store.upsertMatch({ id: 'm1', game: 'valorant', started_at: Date.now() - 60000, status: 'ended', detail: JSON.stringify({ players }) }); const mk = (id: string, text: string | null) => { const f = path.join(dir, 'audio', `${id}.ogg`); fs.mkdirSync(path.dirname(f), { recursive: true }); fs.writeFileSync(f, Buffer.concat([Buffer.from('OggS'), Buffer.alloc(50)])); store.insertUtterance({ id, session_id: null, user_id: 'u1', started_at: Date.now(), ended_at: Date.now() + 1000, audio_path: f, match_id: 'm1' }); if (text !== null) store.updateUtteranceResult(id, { text, raw_text: text, words: [], noise: false, noise_reason: null, confidence: 0.4, lufs: -30, gain_db: 0, model: 'm', status: 'precise' }); return f; }; const reqs: any[] = []; const results: Record = {}; const worker: any = Object.assign(new EventEmitter(), { ready: true, request: async (op: string, req: any) => { if (op === 'gpu_info') return { gpus: [] }; if (op === 'models') return { models: [{ name: 'm', installed: true }] }; if (op === 'load') return {}; reqs.push(req); const id = path.basename(req.path, '.ogg'); return { text: '말', raw_text: '말', words: [], noise: false, noise_reason: null, confidence: 0.5, lufs: -30, gain_db: 0, speech_ratio: 1, duration_s: 1, model: 'm', elapsed_ms: 1, ...results[id] }; }, }); const settings: any = () => ({ stt: { realtimeModel: 'm', preciseModel: 'm', device: 'cpu', computeType: 'int8', gameVramReserveMb: 0, reprocessAfterMatch: false }, audio: { targetLufs: -18, noiseSensitivity: 0.5, denoise: false } }); const dict: any = { hotwords: (_ctx: string, extra: string[] = []) => [...extra, '로테'].join(' '), corrections: () => [], candidates: () => [] }; const stt = new SttPipeline(worker, store, dict, new Timeline(store), new Bus(), settings); const wait = async (fn: () => boolean) => { const t = Date.now(); while (!fn()) { if (Date.now() - t > 5000) throw new Error('timeout'); await new Promise((r) => setTimeout(r, 10)); } }; return { store, stt, mk, reqs, results, wait }; } test('핫워드: 선수 이름은 한글이 들어간 것만 넣고, 그 이름을 워커에 되풀이 확인용으로 넘긴다', async () => { const s = setup(); await s.stt.load('realtime', 'm'); s.mk('a1', null); s.stt.enqueue('a1', 'realtime'); await s.wait(() => s.store.getUtterance('a1')!.status !== 'pending'); const hw: string[] = s.reqs[0].hotwords.split(' '); assert.ok(hw.includes('제트') && hw.includes('레이즈') && hw.includes('세이지'), '요원 이름은 그대로'); assert.ok(hw.includes('노곤노곤탐방가')); assert.ok(!hw.includes('QQQWWWQQQ') && !hw.includes('Sky'), '한글 없는 닉네임은 핫워드에 넣지 않는다'); assert.deepEqual(s.reqs[0].player_names, ['노곤노곤탐방가']); }); test('예전 발화 다시 보기 (한 번만): 이름을 잘못 적은 발화는 정밀 모델로 다시 변환, 음성 파일이 없으면 숨김, 고친 발화 · 실제 말은 그대로', async () => { const s = setup(); const fRedo = s.mk('e1', 'QQQWWWQ'); s.mk('e2', 'QQQWWWQ'); s.store.markAudioDeleted('e2'); s.mk('e3', '아이고, 점프티... 아, 갔다.'); s.mk('e4', 'QQQWWWQ'); s.store.db.prepare('UPDATE utterances SET corrected=1 WHERE id=?').run('e4'); const fFixed = s.mk('e5', 'QQQWWWQ'); // e1: 다시 들어 보니 말소리가 아니었다 → 잡음으로 숨기고 파일 삭제. e5: 다시 들어 보니 실제 말 s.results.e1 = { text: null, raw_text: null, noise: true, noise_reason: 'vad' }; s.results.e5 = { text: '아 갔다', raw_text: '아 갔다' }; await s.stt.load('precise', 'm'); s.stt.resumePending(); await s.wait(() => s.reqs.length >= 2 && !s.stt.status.processing && s.stt.status.queue === 0); assert.deepEqual(s.reqs.map((r) => path.basename(r.path, '.ogg')).sort(), ['e1', 'e5'], '정밀 모델로 이미 변환한 발화도 다시 변환'); assert.equal(s.reqs[0].slot, 'precise'); const e1 = s.store.getUtterance('e1')!; assert.equal(e1.noise, 1); assert.equal(e1.text, null); assert.ok(!fs.existsSync(fRedo)); const e2 = s.store.getUtterance('e2')!; assert.equal(e2.noise, 1); assert.equal(e2.noise_reason, 'name_echo'); assert.equal(e2.text, null); assert.equal(s.store.getUtterance('e3')!.text, '아이고, 점프티... 아, 갔다.'); assert.equal(s.store.getUtterance('e4')!.text, 'QQQWWWQ', '사람이 고친 발화는 그대로'); assert.equal(s.store.getUtterance('e5')!.text, '아 갔다'); assert.ok(fs.existsSync(fFixed)); // 두 번째 시작에서는 다시 보지 않는다 s.mk('e6', 'QQQWWWQ'); s.stt.resumePending(); await new Promise((r) => setTimeout(r, 50)); assert.equal(s.reqs.length, 2); });