From 3c4c3e0280431e305b25a55f52fbb7a8fab3200b Mon Sep 17 00:00:00 2001 From: Makito Date: Fri, 1 Aug 2025 23:22:43 +0900 Subject: [PATCH] fix(stage-ui): enqueue 2x TTS_FLUSH_INSTRUCTION tokens (#342) --- packages/stage-ui/src/stores/chat.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/stage-ui/src/stores/chat.ts b/packages/stage-ui/src/stores/chat.ts index 22caab36d..c569a9ae0 100644 --- a/packages/stage-ui/src/stores/chat.ts +++ b/packages/stage-ui/src/stores/chat.ts @@ -183,10 +183,15 @@ export const useChatStore = defineStore('chat', () => { }) fullText += textPart } - await parser.end() // Instruct the TTS pipeline to flush - slicesQueue.add({ type: 'text', text: TTS_FLUSH_INSTRUCTION }) + // 2x TTS_FLUSH_INSTRUCTION tokens are used: + // - One should be left in the grapheme cluster reader + // - The other should be left in the TTS chunking reader + // Because both readers will never be closed in the lifecycle of the app + slicesQueue.add({ type: 'text', text: `${TTS_FLUSH_INSTRUCTION}${TTS_FLUSH_INSTRUCTION}` }) + + await parser.end() for (const hook of onStreamEndHooks.value) { await hook()