From 0351be6018b5dfea108af80fb8aa1ad379561780 Mon Sep 17 00:00:00 2001 From: wangxiangshun Date: Sun, 19 Oct 2025 18:52:00 +0800 Subject: [PATCH] =?UTF-8?q?TTS=20=E8=BF=94=E5=9B=9E=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/vetti/socket/ChatWebSocketHandler.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/vetti-admin/src/main/java/com/vetti/socket/ChatWebSocketHandler.java b/vetti-admin/src/main/java/com/vetti/socket/ChatWebSocketHandler.java index dd0c9ea..7304db5 100644 --- a/vetti-admin/src/main/java/com/vetti/socket/ChatWebSocketHandler.java +++ b/vetti-admin/src/main/java/com/vetti/socket/ChatWebSocketHandler.java @@ -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)) {