TTS 返回语音优化

This commit is contained in:
2025-10-19 18:52:00 +08:00
parent 7a7ff415c6
commit 0351be6018

View File

@@ -144,10 +144,10 @@ public class ChatWebSocketHandler {
log.info("3、开始进行AI回答时间:{}",System.currentTimeMillis()/1000);
//持续返回数据流给客户端
try {
// String resultOutPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + "110_"+resultFileName;
handleVoice(resultPathUrl,resultPathUrl);
String resultOutPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + "110_"+resultFileName;
handleVoice(resultPathUrl,resultOutPathUrl);
//文件转换成文件流
ByteBuffer outByteBuffer = convertFileToByteBuffer(resultPathUrl);
ByteBuffer outByteBuffer = convertFileToByteBuffer(resultOutPathUrl);
//发送文件流数据
session.getBasicRemote().sendBinary(outByteBuffer);
// 发送响应确认
@@ -426,7 +426,14 @@ public class ChatWebSocketHandler {
System.out.println("音频长度小于300毫秒无法截断");
return;
}
File file = new File(outputPath);
// 创建空文件
boolean isCreated = file.createNewFile();
if (isCreated) {
System.out.println("空文件创建成功:" + file.getAbsolutePath());
} else {
System.out.println("文件已存在:" + file.getAbsolutePath());
}
// 4. 读取并保留前半部分去掉最后300毫秒
try (InputStream in = new FileInputStream(inputPath);
OutputStream out = new FileOutputStream(outputPath)) {