fix(tts): drop stale message before moving voice channel
A slow older message from channel A could still call getSession()/moveTo() after a newer message from channel B was already playing, dragging the bot back to A. Check arrival order before touching the session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,11 @@ export class TTSClient {
|
|||||||
const { buf, parts, failed } = await this.getSource(text, voice);
|
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`);
|
Logger.info(`[TTS] guild=${channel.guild.id} seq=${seq} parts=${parts} failed=${failed} synth=${Date.now() - startedAt}ms`);
|
||||||
if (!buf) return;
|
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);
|
const session = this.getSession(channel.guild, voiceChannel);
|
||||||
session.play(buf, seq);
|
session.play(buf, seq);
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ export class VoiceSession {
|
|||||||
}, this.endTimeMs);
|
}, this.endTimeMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isStale(seq: number) {
|
||||||
|
return seq <= this.lastPlayedSeq;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 새 TTS가 들어오면 이전 재생을 의도적으로 interrupt한다 (큐잉 없음).
|
* 새 TTS가 들어오면 이전 재생을 의도적으로 interrupt한다 (큐잉 없음).
|
||||||
* 다중 사용자 환경에서 모든 메시지를 큐로 쌓으면 자기 발화가 수십 초
|
* 다중 사용자 환경에서 모든 메시지를 큐로 쌓으면 자기 발화가 수십 초
|
||||||
@@ -98,7 +102,7 @@ export class VoiceSession {
|
|||||||
*/
|
*/
|
||||||
public async play(mp3Buf: Buffer, seq: number) {
|
public async play(mp3Buf: Buffer, seq: number) {
|
||||||
if (this.isSessionEnd) return;
|
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)`);
|
Logger.info(`${this.tag} seq=${seq} dropped (newer seq=${this.lastPlayedSeq} already playing)`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user