|
|
|
@ -343,14 +343,18 @@ class ChatController extends GetxController { |
|
|
|
(chunk) { |
|
|
|
if (_shouldCancelAiResponse) return; |
|
|
|
|
|
|
|
fullResponse += chunk; |
|
|
|
|
|
|
|
// 更新加载中的消息内容 |
|
|
|
_updateLoadingMessage(fullResponse); |
|
|
|
|
|
|
|
// 如果TTS启用,使用流式处理发送到TTS |
|
|
|
if (isTtsEnabled.value) { |
|
|
|
_ttsService.speakStream(chunk); |
|
|
|
if (chunk is Map) { |
|
|
|
_updateLoadingMessage(data: chunk); |
|
|
|
} else { |
|
|
|
fullResponse += chunk; |
|
|
|
|
|
|
|
// 更新加载中的消息内容 |
|
|
|
_updateLoadingMessage(content: fullResponse); |
|
|
|
|
|
|
|
// 如果TTS启用,使用流式处理发送到TTS |
|
|
|
if (isTtsEnabled.value) { |
|
|
|
_ttsService.speakStream(chunk); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
onDone: () { |
|
|
|
@ -402,13 +406,22 @@ class ChatController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
// 更新加载中的消息 |
|
|
|
void _updateLoadingMessage(String content) { |
|
|
|
void _updateLoadingMessage({Map? data, String? content}) { |
|
|
|
final index = messages.indexWhere((m) => m.isLoading); |
|
|
|
if (index != -1) { |
|
|
|
messages[index] = messages[index].copyWith( |
|
|
|
content: content, |
|
|
|
isLoading: true, |
|
|
|
); |
|
|
|
if (data != null) { |
|
|
|
Map messagesData = messages[index].data ?? {}; |
|
|
|
messages[index] = messages[index].copyWith( |
|
|
|
data: {...messagesData, ...data}, |
|
|
|
isLoading: true, |
|
|
|
); |
|
|
|
} |
|
|
|
if (content != null) { |
|
|
|
messages[index] = messages[index].copyWith( |
|
|
|
content: content, |
|
|
|
isLoading: true, |
|
|
|
); |
|
|
|
} |
|
|
|
messages.refresh(); |
|
|
|
_scrollToBottom(); |
|
|
|
} |
|
|
|
|