STT 数据流处理-试一下合并后的格式

This commit is contained in:
2025-10-20 13:19:59 +08:00
parent 556ec0c268
commit 51a81a7346

View File

@@ -100,6 +100,7 @@ public class OpenAiStreamClient {
// 检查是否为结束标记 // 检查是否为结束标记
if (data.equals("[DONE]")) { if (data.equals("[DONE]")) {
listener.onMessage(bufferStr.toString()); listener.onMessage(bufferStr.toString());
bufferStr.replace(0, bufferStr.length(), "");
listener.onComplete(); listener.onComplete();
break; break;
} }
@@ -113,19 +114,12 @@ public class OpenAiStreamClient {
.getStr("content"); .getStr("content");
if (content != null && !content.isEmpty()) { if (content != null && !content.isEmpty()) {
if(punctuationStr.contains(content)){ //加入缓冲区
//说明有标点啦,直接返回
bufferStr.append(content); bufferStr.append(content);
if(punctuationStr.contains(content.trim())){
//说明有标点啦,直接返回
listener.onMessage(bufferStr.toString()); listener.onMessage(bufferStr.toString());
bufferStr.replace(0, bufferStr.length(), ""); 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); // listener.onMessage(content);