同步 oneApp 的代码
This commit is contained in:
@@ -59,7 +59,8 @@ class ChatSseService {
|
||||
txt = txt.substring(0, imgStart) + txt.substring(imgEnd + 1);
|
||||
imgStart = txt.indexOf('![');
|
||||
}
|
||||
|
||||
// 彻底移除 markdown 有序/无序列表序号(如 1.、2.、-、*、+)
|
||||
txt = txt.replaceAll(RegExp(r'(^|\n)[ \t]*[0-9]+\.[ \t]*'), '\n');
|
||||
txt = txt.replaceAll(RegExp(r'(^|\n)[ \t]*[-\*\+][ \t]+'), '\n');
|
||||
// 分句符
|
||||
RegExp enders = isChinese ? zhEnders : enEnders;
|
||||
@@ -76,14 +77,8 @@ class ChatSseService {
|
||||
}
|
||||
// 只在达到完整句子时调用 TtsUtil.send
|
||||
for (final s in sentences) {
|
||||
String ttsStr=CommonUtil.cleanText(s, true)+"\n";
|
||||
|
||||
ttsStr = ttsStr.replaceAllMapped(
|
||||
RegExp(r'(?<!\s)(\d+)(?!\s)'),
|
||||
(m) => ' ${m.group(1)} ',
|
||||
);
|
||||
|
||||
print("发送数据到TTS: $ttsStr");
|
||||
String ttsStr=CommonUtil.cleanText(s, true);
|
||||
// print("发送数据到TTS: $ttsStr");
|
||||
TtsUtil.send(ttsStr);
|
||||
}
|
||||
// 缓存剩余不完整部分
|
||||
|
||||
@@ -21,7 +21,7 @@ import 'command_service.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
class MessageService extends ChangeNotifier {
|
||||
static const MethodChannel _asrChannel = MethodChannel('com.example.ai_chat_assistant/asr');
|
||||
static const MethodChannel _asrChannel = MethodChannel('com.example.ai_chat_assistant/ali_sdk');
|
||||
|
||||
static final MessageService _instance = MessageService._internal();
|
||||
|
||||
@@ -61,7 +61,7 @@ class MessageService extends ChangeNotifier {
|
||||
// final AudioRecorderService _audioService = AudioRecorderService();
|
||||
// final VoiceRecognitionService _recognitionService = VoiceRecognitionService();
|
||||
final TextClassificationService _classificationService =
|
||||
TextClassificationService();
|
||||
TextClassificationService();
|
||||
final VehicleCommandService _vehicleCommandService = VehicleCommandService();
|
||||
|
||||
final List<ChatMessage> _messages = [];
|
||||
@@ -106,7 +106,6 @@ class MessageService extends ChangeNotifier {
|
||||
abortReply();
|
||||
_latestUserMessageId = null;
|
||||
_latestAssistantMessageId = null;
|
||||
_isReplyAborted = false;
|
||||
changeState(MessageServiceState.recording);
|
||||
_latestUserMessageId = addMessage("", true, MessageStatus.listening);
|
||||
_asrChannel.invokeMethod("startAsr");
|
||||
@@ -138,6 +137,7 @@ class MessageService extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
_isReplyAborted = false;
|
||||
changeState(MessageServiceState.recognizing);
|
||||
_asrChannel.invokeMethod("stopAsr");
|
||||
_asrCompleter = Completer<String>();
|
||||
@@ -227,7 +227,7 @@ class MessageService extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
final vehicleCommandResponse =
|
||||
await _vehicleCommandService.getCommandFromText(text);
|
||||
await _vehicleCommandService.getCommandFromText(text);
|
||||
if (vehicleCommandResponse == null) {
|
||||
if (_isReplyAborted) {
|
||||
return;
|
||||
@@ -269,12 +269,12 @@ class MessageService extends ChangeNotifier {
|
||||
bool isSuccess;
|
||||
if (containOpenAC && command.type == VehicleCommandType.changeACTemp) {
|
||||
isSuccess = await Future.delayed(const Duration(milliseconds: 2000),
|
||||
() => processCommand(command, isChinese));
|
||||
() => processCommand(command, isChinese));
|
||||
} else {
|
||||
isSuccess = await processCommand(command, isChinese);
|
||||
}
|
||||
if (isSuccess) {
|
||||
successCommandList.add(command.type.name);
|
||||
successCommandList.add(isChinese ? command.type.chinese : command.type.english);
|
||||
}
|
||||
}
|
||||
replaceMessage(
|
||||
@@ -286,7 +286,7 @@ class MessageService extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
String controlResponse =
|
||||
await _vehicleCommandService.getControlResponse(successCommandList);
|
||||
await _vehicleCommandService.getControlResponse(successCommandList);
|
||||
if (_isReplyAborted || controlResponse.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user