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