diff --git a/src/classes/TTSClient.ts b/src/classes/TTSClient.ts index e10bd13..69b18ec 100644 --- a/src/classes/TTSClient.ts +++ b/src/classes/TTSClient.ts @@ -76,6 +76,11 @@ export class TTSClient { const { buf, parts, failed } = await this.getSource(text, voice); Logger.info(`[TTS] guild=${channel.guild.id} seq=${seq} parts=${parts} failed=${failed} synth=${Date.now() - startedAt}ms`); if (!buf) return; + // 더 최신 채팅이 이미 재생 중이면 채널 이동(getSession → moveTo) 전에 버린다. + if (this.map.get(channel.guild.id)?.isStale(seq)) { + Logger.info(`[TTS] guild=${channel.guild.id} seq=${seq} dropped (newer message already playing)`); + return; + } const session = this.getSession(channel.guild, voiceChannel); session.play(buf, seq); diff --git a/src/classes/VoiceSession.ts b/src/classes/VoiceSession.ts index ef4afd9..cffcbbe 100644 --- a/src/classes/VoiceSession.ts +++ b/src/classes/VoiceSession.ts @@ -87,6 +87,10 @@ export class VoiceSession { }, this.endTimeMs); } + public isStale(seq: number) { + return seq <= this.lastPlayedSeq; + } + /** * 새 TTS가 들어오면 이전 재생을 의도적으로 interrupt한다 (큐잉 없음). * 다중 사용자 환경에서 모든 메시지를 큐로 쌓으면 자기 발화가 수십 초 @@ -98,7 +102,7 @@ export class VoiceSession { */ public async play(mp3Buf: Buffer, seq: number) { if (this.isSessionEnd) return; - if (seq <= this.lastPlayedSeq) { + if (this.isStale(seq)) { Logger.info(`${this.tag} seq=${seq} dropped (newer seq=${this.lastPlayedSeq} already playing)`); return; }