TTS 返回语音优化
This commit is contained in:
@@ -144,10 +144,10 @@ public class ChatWebSocketHandler {
|
|||||||
log.info("3、开始进行AI回答时间:{}",System.currentTimeMillis()/1000);
|
log.info("3、开始进行AI回答时间:{}",System.currentTimeMillis()/1000);
|
||||||
//持续返回数据流给客户端
|
//持续返回数据流给客户端
|
||||||
try {
|
try {
|
||||||
// String resultOutPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + "110_"+resultFileName;
|
String resultOutPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + "110_"+resultFileName;
|
||||||
handleVoice(resultPathUrl,resultPathUrl);
|
handleVoice(resultPathUrl,resultOutPathUrl);
|
||||||
//文件转换成文件流
|
//文件转换成文件流
|
||||||
ByteBuffer outByteBuffer = convertFileToByteBuffer(resultPathUrl);
|
ByteBuffer outByteBuffer = convertFileToByteBuffer(resultOutPathUrl);
|
||||||
//发送文件流数据
|
//发送文件流数据
|
||||||
session.getBasicRemote().sendBinary(outByteBuffer);
|
session.getBasicRemote().sendBinary(outByteBuffer);
|
||||||
// 发送响应确认
|
// 发送响应确认
|
||||||
@@ -426,7 +426,14 @@ public class ChatWebSocketHandler {
|
|||||||
System.out.println("音频长度小于300毫秒,无法截断");
|
System.out.println("音频长度小于300毫秒,无法截断");
|
||||||
return;
|
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毫秒)
|
// 4. 读取并保留前半部分(去掉最后300毫秒)
|
||||||
try (InputStream in = new FileInputStream(inputPath);
|
try (InputStream in = new FileInputStream(inputPath);
|
||||||
OutputStream out = new FileOutputStream(outputPath)) {
|
OutputStream out = new FileOutputStream(outputPath)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user