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>
This commit is contained in:
@@ -10,7 +10,8 @@ import { diffWords, Dictionary } from '../src/core/dict/dictionary.ts';
|
||||
import { realignWords } from '../src/core/api/server.ts';
|
||||
import { processMatchDetails } from '../src/core/games/valorant.ts';
|
||||
import { GameAssets } from '../src/core/games/assets.ts';
|
||||
import { OggOpusWriter, opusSamples, SILENCE_FRAME } from '../src/core/discord/ogg.ts';
|
||||
import { OggOpusWriter, opusSamples, removeInsertedSilence, SILENCE_FRAME } from '../src/core/discord/ogg.ts';
|
||||
import { Utterance, tagRtp, tapRtp } from '../src/core/discord/recorder.ts';
|
||||
import { Retention } from '../src/core/retention.ts';
|
||||
import { makeValDetails, SELF } from './fixtures/make-val-details.ts';
|
||||
|
||||
@@ -34,6 +35,81 @@ test('Ogg Opus writer: ffmpeg 가 읽을 수 있고 길이가 맞다', () => {
|
||||
execFileSync('ffmpeg', ['-v', 'error', '-i', out, '-f', 'null', '-']);
|
||||
});
|
||||
|
||||
test('녹음기: 패킷이 몰려 와도 말 중간에 무음을 넣지 않는다 (RTP 타임스탬프 기준)', () => {
|
||||
// 게임 중 실제 수신 모양: 20ms 간격으로 만든 패킷이 40~60ms 마다 2~3개씩 한꺼번에 도착 (v1.3.5 사용자 파일 "##.##.##")
|
||||
const dir = tmp();
|
||||
const voice = Array.from({ length: 100 }, (_, i) => Buffer.from([0x78, i & 0xff, 0x01]));
|
||||
const u = new Utterance(dir, 1_000_000);
|
||||
let now = 1_000_020;
|
||||
let seq = 65530; // 순번이 한 바퀴 도는 경우도 함께
|
||||
let ts = 4294967296 - 960 * 10; // 타임스탬프도 한 바퀴 돔
|
||||
let filled = 0;
|
||||
for (let i = 0; i < voice.length; i++) {
|
||||
if (i === 60) {
|
||||
// 진짜 쉼 0.4초: 패킷 20개 자리가 비었다
|
||||
seq = (seq + 20) & 0xffff;
|
||||
ts = (ts + 960 * 20) >>> 0;
|
||||
now += 400;
|
||||
}
|
||||
if (i % 3 === 0) now += 60; // 3개씩 몰려 도착
|
||||
filled += Math.max(0, u.place(tagRtp(voice[i], { seq, ts }), now, 1000));
|
||||
seq = (seq + 1) & 0xffff;
|
||||
ts = (ts + 960) >>> 0;
|
||||
}
|
||||
// 중복 패킷은 버린다
|
||||
assert.equal(u.place(tagRtp(Buffer.from([0x78, 0, 0]), { seq: (seq - 1) & 0xffff, ts: (ts - 960) >>> 0 }), now, 1000), -1);
|
||||
assert.equal(filled, 20, '진짜 쉼만 채운다');
|
||||
assert.equal(u.writer.samples, (100 + 20) * 960);
|
||||
u.writer.close();
|
||||
});
|
||||
|
||||
test('예전 녹음 고치기: 말 중간에 끼운 무음만 빼고 말 끝 무음은 남긴다', () => {
|
||||
const f = path.join(tmp(), 'old.ogg');
|
||||
const w = new OggOpusWriter(f);
|
||||
const v = (i: number) => Buffer.from([0x78, i, 1]);
|
||||
// "##.##.##" + 진짜 쉼(10) + "##" + 말 끝 무음 5
|
||||
const seq = [v(1), v(2), SILENCE_FRAME, v(3), v(4), SILENCE_FRAME, v(5), v(6), ...Array(10).fill(SILENCE_FRAME), v(7), v(8), ...Array(5).fill(SILENCE_FRAME)];
|
||||
for (const p of seq) w.write(p);
|
||||
w.close();
|
||||
assert.equal(removeInsertedSilence(f), 2);
|
||||
const after = readOggPackets(fs.readFileSync(f)).slice(2);
|
||||
assert.equal(after.length, seq.length - 2);
|
||||
assert.equal(removeInsertedSilence(f), 0, '두 번 고치지 않는다');
|
||||
execFileSync('ffmpeg', ['-v', 'error', '-i', f, '-f', 'null', '-']);
|
||||
});
|
||||
|
||||
test('녹음기: RTP 시각이 없을 때도 몰려 온 패킷 사이에 무음을 넣지 않는다', () => {
|
||||
const u = new Utterance(tmp(), 1_000_000);
|
||||
let now = 1_000_020;
|
||||
let filled = 0;
|
||||
for (let i = 0; i < 60; i++) {
|
||||
if (i % 3 === 0) now += 60;
|
||||
filled += u.place(Buffer.from([0x78, i, 1]), now, 1000);
|
||||
}
|
||||
assert.equal(filled, 0);
|
||||
now += 500; // 0.5초 쉼 뒤 말
|
||||
filled += u.place(Buffer.from([0x78, 9, 1]), now, 1000);
|
||||
assert.ok(filled >= 18 && filled <= 25, `filled ${filled}`);
|
||||
u.writer.close();
|
||||
});
|
||||
|
||||
test('녹음기: 디스코드 수신기의 RTP 헤더를 패킷에 붙인다', () => {
|
||||
const rtp = Buffer.alloc(16);
|
||||
rtp[0] = 0x80;
|
||||
rtp.writeUInt16BE(1234, 2);
|
||||
rtp.writeUInt32BE(99999, 4);
|
||||
const opus = Buffer.from([0x78, 1, 2]);
|
||||
const receiver = { parsePacket: (_b: Buffer) => opus };
|
||||
assert.equal(tapRtp(receiver), true);
|
||||
assert.equal(tapRtp(receiver), true); // 두 번 감싸지 않음
|
||||
const out = receiver.parsePacket(rtp);
|
||||
const u = new Utterance(tmp(), 0);
|
||||
u.place(out, 20, 1000);
|
||||
assert.equal(u.rtpBase, 99999);
|
||||
assert.equal(u.lastSeq, 1234);
|
||||
u.writer.close();
|
||||
});
|
||||
|
||||
function readOggPackets(buf: Buffer): Buffer[] {
|
||||
const out: Buffer[] = [];
|
||||
let pos = 0;
|
||||
@@ -144,10 +220,10 @@ test('타임라인 조회: 필터·검색·커서', () => {
|
||||
store.updateUtteranceResult('n1', { text: null, raw_text: '시청해 주셔서 감사합니다', words: [], noise: true, noise_reason: 'hallucination', confidence: 0.2, lufs: -40, gain_db: 20, model: 'tiny', status: 'realtime' });
|
||||
let page = tl.query({ limit: 3 });
|
||||
assert.equal(page.items.length, 3);
|
||||
assert.equal(page.items[0].id, 'n1');
|
||||
assert.equal(page.items[0].id, 'x4', '잡음은 보이지 않는다');
|
||||
const page2 = tl.query({ limit: 3, cursor: page.next! });
|
||||
assert.deepEqual(page2.items.map((i) => i.id), ['x2', 'x1', 'x0']);
|
||||
assert.equal(tl.query({ hideNoise: true }).items.length, 5);
|
||||
assert.deepEqual(page2.items.map((i) => i.id), ['x1', 'x0']);
|
||||
assert.equal(tl.query({}).items.length, 5);
|
||||
assert.deepEqual(tl.query({ q: '레이즈 궁' }).items.map((i) => i.id), ['x1']);
|
||||
assert.deepEqual(tl.query({ q: '오퍼' }).items.map((i) => i.id), ['x2']);
|
||||
assert.equal(tl.query({ users: ['u2'] }).items.length, 2);
|
||||
@@ -208,3 +284,27 @@ test('표시 이름: 정한 이름으로 유저 이름 · 지난 범인 분석
|
||||
assert.equal(again.getUser('u1')?.name, '별명');
|
||||
again.close();
|
||||
});
|
||||
|
||||
test('users.updated: 보내는 쪽이 빈 목록을 줘도 실제 유저 목록이 나간다 ("알 수 없음" 버그)', async () => {
|
||||
const { Bus } = await import('../src/core/util/events.ts');
|
||||
const bus = new Bus();
|
||||
bus.usersProvider = () => [{ id: '1', name: '하늘', color: '#fff', avatar: null, excluded: false, riot: [] }];
|
||||
const got: any[] = [];
|
||||
bus.on('live', (e) => got.push(e));
|
||||
bus.live({ type: 'users.updated', data: [] });
|
||||
assert.equal(got[0].data.length, 1);
|
||||
assert.equal(got[0].data[0].name, '하늘');
|
||||
});
|
||||
|
||||
test('녹음 안내 말 속도: 0.1~2.0 으로 자르고 속도마다 따로 캐시한다', async () => {
|
||||
const { Announcer, clampRate } = await import('../src/core/discord/tts.ts');
|
||||
assert.equal(clampRate(0.05), 0.1);
|
||||
assert.equal(clampRate(3), 2);
|
||||
assert.equal(clampRate('x'), 1);
|
||||
const a = new Announcer(tmp(), tmp());
|
||||
const one = a.cachedPath('안내', 'v', 1);
|
||||
assert.equal(one, a.cachedPath('안내', 'v'), '1.0배는 예전 캐시 그대로');
|
||||
assert.notEqual(a.cachedPath('안내', 'v', 1.5), one);
|
||||
assert.ok(a.cachedPath('안내', 'v', 0.3).endsWith('.ogg'), '0.5배보다 느리면 워커가 만든 Ogg');
|
||||
assert.ok(a.cachedPath('안내', 'v', 0.5).endsWith('.webm'));
|
||||
});
|
||||
|
||||
@@ -63,11 +63,22 @@ test('E2E: 발화 → STT 워커 → DB → 실시간 이벤트 → 기록 API',
|
||||
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.equal(page.items.length, 3);
|
||||
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);
|
||||
|
||||
@@ -65,6 +65,14 @@ test('발로란트·롤 어댑터: 가짜 Riot 서버로 경기 시작→채팅
|
||||
await until(() => store.events('val-m-0001').filter((e) => e.type === 'chat').length === 2, 5000, 'chat');
|
||||
mock.st.ally = 1;
|
||||
await until(() => store.events('val-m-0001').some((e) => e.type === 'round_end'), 5000, 'live round');
|
||||
// 지금 게임 상태 (앱 게임 연동 탭 · 사이트)
|
||||
const lv = gm.live().find((g) => g.game === 'valorant')!;
|
||||
assert.equal(lv.phase, '경기 중');
|
||||
assert.equal(lv.mode, '경쟁전');
|
||||
assert.equal(lv.round, 2);
|
||||
assert.deepEqual(lv.score, { ally: 1, enemy: 0 });
|
||||
assert.equal(lv.self?.name, '하늘#KR1');
|
||||
await until(() => live.some((e) => e.type === 'games.state' && e.data[0].inMatch), 5000, 'games.state');
|
||||
// 발화 하나 (경기 중)
|
||||
store.insertUtterance({ id: 'u-val', session_id: null, user_id: 'owner', started_at: Date.now(), ended_at: Date.now() + 500, audio_path: null, match_id: gm.liveMatchAt(Date.now()) });
|
||||
assert.equal(store.getUtterance('u-val')!.match_id, 'val-m-0001');
|
||||
@@ -93,6 +101,13 @@ test('발로란트·롤 어댑터: 가짜 Riot 서버로 경기 시작→채팅
|
||||
]);
|
||||
await until(() => !!store.getMatch('lol-7001'), 5000, 'lol start');
|
||||
await until(() => store.events('lol-7001').length >= 4, 5000, 'lol events');
|
||||
const ll = gm.live().find((g) => g.game === 'lol')!;
|
||||
assert.equal(ll.phase, '경기 중');
|
||||
assert.equal(ll.mode, '솔로 랭크');
|
||||
assert.equal(ll.self?.character, '아리');
|
||||
assert.equal(ll.self?.kda, '3/1/2');
|
||||
assert.deepEqual(ll.teamKills, { ally: 4, enemy: 2 });
|
||||
assert.equal(ll.gameTimeSec, 120);
|
||||
const lev = store.events('lol-7001');
|
||||
const chat = lev.find((e) => e.type === 'chat')!;
|
||||
assert.equal(JSON.parse(chat.data).text, '정글 갱 갈게요');
|
||||
@@ -121,3 +136,23 @@ test('발로란트·롤 어댑터: 가짜 Riot 서버로 경기 시작→채팅
|
||||
store.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('발로란트 데스매치: 경기 전체가 라운드 1개로 와도 라운드 · 에이스를 만들지 않는다', async () => {
|
||||
const { processMatchDetails } = await import('../src/core/games/valorant.ts');
|
||||
const { GameAssets } = await import('../src/core/games/assets.ts');
|
||||
const { makeValDetails, SELF } = await import('./fixtures/make-val-details.ts');
|
||||
const md = makeValDetails(1_000_000);
|
||||
md.matchInfo.queueID = 'deathmatch';
|
||||
// 한 "라운드"에 한 사람이 5킬 (데스매치에서는 흔함)
|
||||
const r0 = md.roundResults[0];
|
||||
const ps = r0.playerStats.find((p: any) => p.subject === SELF)!;
|
||||
const k = ps.kills[0];
|
||||
ps.kills = Array.from({ length: 6 }, (_, i) => ({ ...k, gameTime: k.gameTime + i * 1000, victim: `enemy-${i}` }));
|
||||
md.roundResults = [r0];
|
||||
const res = processMatchDetails(md, SELF, new GameAssets(tmp()), 'val-dm', 1_000_000);
|
||||
assert.equal(res.rounds.length, 0);
|
||||
assert.equal(res.roundsDetail.length, 0);
|
||||
assert.ok(!res.events.some((e) => e.type === 'round_end' || e.type === 'ace' || e.type === 'multikill'));
|
||||
assert.ok(res.events.filter((e) => e.type === 'kill').length >= 6);
|
||||
assert.equal(res.result.score, null);
|
||||
});
|
||||
|
||||
@@ -61,6 +61,7 @@ export async function startMockRiot(dir: string) {
|
||||
],
|
||||
[/^\/chat\/v4\/presences$/, () => [200, { presences: [{ puuid: SELF, product: 'valorant', private: presence() }] }]],
|
||||
[/^\/chat\/v6\/messages$/, () => [200, { messages: st.valMessages }]],
|
||||
[/^\/chat\/v1\/session$/, () => [200, { game_name: '하늘', game_tag: 'KR1', puuid: SELF }]],
|
||||
// ---- glz
|
||||
[/^\/core-game\/v1\/players\/(.+)$/, () => (st.valState === 'INGAME' ? [200, { Subject: SELF, MatchID: st.valMatchId }] : [404, { errorCode: 'RESOURCE_NOT_FOUND' }])],
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user