TTS 返回语音优化

This commit is contained in:
2025-10-19 19:29:41 +08:00
parent 3f96c2e2f1
commit 9febb08b4f

View File

@@ -104,6 +104,7 @@ public class OpenAiStreamClient {
String data = line.substring(6).trim();
// 检查是否为结束标记
if (data.equals("[DONE]")) {
listener.onMessage(bufferStr.toString());
listener.onComplete();
break;
}
@@ -116,22 +117,23 @@ public class OpenAiStreamClient {
.getJSONObject("delta")
.getStr("content");
// if (content != null && !content.isEmpty()) {
// if(punctuationSet.contains(content)){
// //说明有标点啦,直接返回
// bufferStr.append(content);
// listener.onMessage(bufferStr.toString());
// }else{
// //加入缓冲区
// if(StrUtil.isEmpty(bufferStr.toString())){
// bufferStr.append(content);
// }else {
// bufferStr.append(" ").append(content);
// }
// }
//
// }
listener.onMessage(content);
if (content != null && !content.isEmpty()) {
if(punctuationSet.contains(content)){
//说明有标点啦,直接返回
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);
} catch (Exception e) {
listener.onError(new IOException("Parse error: " + e.getMessage()));
}