STT 数据流处理-试一下合并后的格式
This commit is contained in:
@@ -100,6 +100,7 @@ public class OpenAiStreamClient {
|
||||
// 检查是否为结束标记
|
||||
if (data.equals("[DONE]")) {
|
||||
listener.onMessage(bufferStr.toString());
|
||||
bufferStr.replace(0, bufferStr.length(), "");
|
||||
listener.onComplete();
|
||||
break;
|
||||
}
|
||||
@@ -113,19 +114,12 @@ public class OpenAiStreamClient {
|
||||
.getStr("content");
|
||||
|
||||
if (content != null && !content.isEmpty()) {
|
||||
if(punctuationStr.contains(content)){
|
||||
//加入缓冲区
|
||||
bufferStr.append(content);
|
||||
if(punctuationStr.contains(content.trim())){
|
||||
//说明有标点啦,直接返回
|
||||
bufferStr.append(content);
|
||||
listener.onMessage(bufferStr.toString());
|
||||
bufferStr.replace(0, bufferStr.length(), "");
|
||||
// bufferStr = new StringBuffer();
|
||||
}else{
|
||||
//加入缓冲区
|
||||
if(StrUtil.isEmpty(bufferStr.toString())){
|
||||
bufferStr.append(content);
|
||||
}else {
|
||||
bufferStr.append(" ").append(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
// listener.onMessage(content);
|
||||
|
||||
Reference in New Issue
Block a user