[bugfix] chat bubble error and Pronounce ID.UNYX error
This commit is contained in:
@@ -62,23 +62,21 @@ class _FullScreenState extends State<FullScreen> {
|
|||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Consumer<MessageService>(
|
child: Consumer<MessageService>(
|
||||||
builder: (context, handler, child) {
|
builder: (context, messageService, child) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_scrollToBottom();
|
_scrollToBottom();
|
||||||
});
|
});
|
||||||
final messageService = context.read<MessageService>();
|
if (messageService.messages.isEmpty) {
|
||||||
List<ChatMessage> fullScreenMessages = List.from(handler.messages);
|
// Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
if (fullScreenMessages.isEmpty) {
|
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
|
||||||
String text = Intl.getCurrentLocale().startsWith('zh')
|
String text = Intl.getCurrentLocale().startsWith('zh')
|
||||||
? "您好,我是众众,请问有什么可以帮您?"
|
? "您好,我是众众,请问有什么可以帮您?"
|
||||||
: "Hi, I'm Zhongzhong, may I help you ? ";
|
: "Hi, I'm Zhongzhong, may I help you ? ";
|
||||||
messageService.addMessage(text, false, MessageStatus.normal);
|
messageService.addMessage(text, false, MessageStatus.normal);
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
return ChatBox(
|
return ChatBox(
|
||||||
scrollController: _scrollController,
|
scrollController: _scrollController,
|
||||||
messages: handler.messages,
|
messages: messageService.messages,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -110,8 +110,7 @@ class _PartScreenState extends State<PartScreen> {
|
|||||||
_scrollToBottom();
|
_scrollToBottom();
|
||||||
});
|
});
|
||||||
return Consumer<MessageService>(
|
return Consumer<MessageService>(
|
||||||
builder: (context, handler, child) {
|
builder: (context, messageService, child) {
|
||||||
final messages = handler.messages;
|
|
||||||
return AnimatedContainer(
|
return AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 180),
|
duration: const Duration(milliseconds: 180),
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
@@ -145,7 +144,7 @@ class _PartScreenState extends State<PartScreen> {
|
|||||||
child: ChatBox(
|
child: ChatBox(
|
||||||
scrollController:
|
scrollController:
|
||||||
_scrollController,
|
_scrollController,
|
||||||
messages: messages,
|
messages: messageService.messages,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ class ChatSseService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tempText += textChunk;
|
tempText += textChunk;
|
||||||
|
if (tempText.contains("ID.")) {
|
||||||
|
tempText = tempText.replaceAllMapped(
|
||||||
|
RegExp(r'ID\.', caseSensitive: false), (m) => 'ID ');
|
||||||
|
}
|
||||||
int endIndex = _getCompleteTextEndIndex(tempText);
|
int endIndex = _getCompleteTextEndIndex(tempText);
|
||||||
String completeText = CommonUtil.cleanText(tempText.substring(0, endIndex).trim(), true);
|
String completeText = CommonUtil.cleanText(tempText.substring(0, endIndex).trim(), true);
|
||||||
if (completeText.isNotEmpty) {
|
if (completeText.isNotEmpty) {
|
||||||
@@ -136,7 +140,7 @@ class ChatSseService {
|
|||||||
|
|
||||||
int _getCompleteTextEndIndex(String buffer) {
|
int _getCompleteTextEndIndex(String buffer) {
|
||||||
// 支持句号、问号、感叹号和换行符作为分割依据
|
// 支持句号、问号、感叹号和换行符作为分割依据
|
||||||
final sentenceEnders = RegExp(r'[,!?:,。!?:\n]');
|
final sentenceEnders = RegExp(r'[,.!?:,。!?:\n]');
|
||||||
final matches = sentenceEnders.allMatches(buffer);
|
final matches = sentenceEnders.allMatches(buffer);
|
||||||
return matches.isEmpty ? 0 : matches.last.end;
|
return matches.isEmpty ? 0 : matches.last.end;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,15 @@ class MessageService extends ChangeNotifier {
|
|||||||
replaceMessage(id: _latestUserMessageId!, text: call.arguments);
|
replaceMessage(id: _latestUserMessageId!, text: call.arguments);
|
||||||
break;
|
break;
|
||||||
case "onAsrStop":
|
case "onAsrStop":
|
||||||
|
int index = findMessageIndexById(_latestUserMessageId!);
|
||||||
|
if (index == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final message = _messages[index];
|
||||||
|
if (message.text.isEmpty) {
|
||||||
|
removeMessageById(_latestUserMessageId!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
replaceMessage(
|
replaceMessage(
|
||||||
id: _latestUserMessageId!, status: MessageStatus.normal);
|
id: _latestUserMessageId!, status: MessageStatus.normal);
|
||||||
if (_asrCompleter != null && !_asrCompleter!.isCompleted) {
|
if (_asrCompleter != null && !_asrCompleter!.isCompleted) {
|
||||||
|
|||||||
@@ -50,8 +50,13 @@ class CommonUtil {
|
|||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
if (forTts) {
|
if (forTts) {
|
||||||
cleanedText = cleanedText.replaceAllMapped(
|
if (cleanedText.contains("ID.UNYX")) {
|
||||||
RegExp(r'ID\.UNYX', caseSensitive: false), (m) => 'I D Unix');
|
cleanedText = cleanedText.replaceAllMapped(
|
||||||
|
RegExp(r'ID\.UNYX', caseSensitive: false), (m) => 'ID Unix');
|
||||||
|
} else {
|
||||||
|
cleanedText = cleanedText.replaceAllMapped(
|
||||||
|
RegExp(r'UNYX', caseSensitive: false), (m) => 'Unix');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cleanedText;
|
return cleanedText;
|
||||||
|
|||||||
@@ -61,30 +61,31 @@ class _ChatBubbleState extends State<ChatBubble> {
|
|||||||
),
|
),
|
||||||
child: _buildAssistantContent(isThinking),
|
child: _buildAssistantContent(isThinking),
|
||||||
)
|
)
|
||||||
: IntrinsicWidth(
|
: Container(
|
||||||
child: Container(
|
constraints: const BoxConstraints(
|
||||||
padding: const EdgeInsets.symmetric(
|
minWidth: 50,
|
||||||
horizontal: 12, vertical: 12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: message.isUser
|
|
||||||
? CommonUtil.commonColor
|
|
||||||
: Colors.white.withValues(alpha: 0.12),
|
|
||||||
borderRadius: message.isUser
|
|
||||||
? BorderRadius.only(
|
|
||||||
topLeft: Radius.circular(12),
|
|
||||||
bottomLeft: Radius.circular(12),
|
|
||||||
bottomRight: Radius.circular(12),
|
|
||||||
)
|
|
||||||
: BorderRadius.only(
|
|
||||||
topRight: Radius.circular(12),
|
|
||||||
bottomLeft: Radius.circular(12),
|
|
||||||
bottomRight: Radius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: message.isUser
|
|
||||||
? _buildUserContent()
|
|
||||||
: _buildAssistantContent(isThinking),
|
|
||||||
),
|
),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12, vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: message.isUser
|
||||||
|
? CommonUtil.commonColor
|
||||||
|
: Colors.white.withOpacity(0.12),
|
||||||
|
borderRadius: message.isUser
|
||||||
|
? BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(12),
|
||||||
|
bottomLeft: Radius.circular(12),
|
||||||
|
bottomRight: Radius.circular(12),
|
||||||
|
)
|
||||||
|
: BorderRadius.only(
|
||||||
|
topRight: Radius.circular(12),
|
||||||
|
bottomLeft: Radius.circular(12),
|
||||||
|
bottomRight: Radius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: message.isUser
|
||||||
|
? _buildUserContent()
|
||||||
|
: _buildAssistantContent(isThinking),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user