[bugfix] can not read the last sentence
This commit is contained in:
@@ -62,6 +62,7 @@ class ChatSseService {
|
||||
if (line.startsWith('data:')) {
|
||||
final jsonStr = line.substring(5).trim();
|
||||
if (jsonStr == '[DONE]' || jsonStr.contains('message_end')) {
|
||||
TtsUtil.complete();
|
||||
onStreamResponse(messageId, responseText, true);
|
||||
break;
|
||||
}
|
||||
@@ -89,8 +90,8 @@ class ChatSseService {
|
||||
await _startTtsFuture;
|
||||
_isFirstData = false;
|
||||
}
|
||||
print("----------------------Send text: " + completeText);
|
||||
completeText += isChinese ? ',' : ',';
|
||||
print("----------------------Send text: " + completeText);
|
||||
TtsUtil.send(completeText);
|
||||
}
|
||||
tempText = tempText.substring(endIndex).trim();
|
||||
@@ -108,6 +109,7 @@ class ChatSseService {
|
||||
} catch (e) {
|
||||
// todo
|
||||
} finally {
|
||||
print("------------------------------finally");
|
||||
resetRequest();
|
||||
}
|
||||
}
|
||||
@@ -123,7 +125,7 @@ class ChatSseService {
|
||||
|
||||
Future<void> abort() async {
|
||||
_isAborted = true;
|
||||
TtsUtil.stopTts();
|
||||
TtsUtil.stop();
|
||||
resetRequest();
|
||||
}
|
||||
|
||||
@@ -136,6 +138,7 @@ class ChatSseService {
|
||||
_currentResponse = null;
|
||||
_isFirstData = true;
|
||||
_isTtsStarted = false;
|
||||
_startTtsFuture = null;
|
||||
}
|
||||
|
||||
int _getCompleteTextEndIndex(String buffer) {
|
||||
|
||||
@@ -57,6 +57,8 @@ class CommonUtil {
|
||||
cleanedText = cleanedText.replaceAllMapped(
|
||||
RegExp(r'UNYX', caseSensitive: false), (m) => 'Unix');
|
||||
}
|
||||
cleanedText = cleanedText.replaceAllMapped(
|
||||
RegExp(r'400-023-4567', caseSensitive: false), (m) => '4 0 0 - 0 2 3 - 4 5 6 7');
|
||||
}
|
||||
|
||||
return cleanedText;
|
||||
|
||||
@@ -17,7 +17,11 @@ class TtsUtil {
|
||||
await execute('send', {'text': text});
|
||||
}
|
||||
|
||||
static Future<void> stopTts() async {
|
||||
static Future<void> complete() async {
|
||||
await execute('complete');
|
||||
}
|
||||
|
||||
static Future<void> stop() async {
|
||||
await execute('stop');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user