AI 添加日期

This commit is contained in:
wangxiangshun
2025-10-07 19:10:45 +08:00
parent 2222d4fa81
commit 05aab54982

View File

@@ -71,23 +71,28 @@ public class ChatWebSocketHandler {
@OnMessage @OnMessage
public void onBinaryMessage(Session session, @PathParam("clientId") String clientId, ByteBuffer byteBuffer) { public void onBinaryMessage(Session session, @PathParam("clientId") String clientId, ByteBuffer byteBuffer) {
try { try {
log.info("1、运行时间:{}",System.currentTimeMillis()/1000);
log.info("客户端ID为:{}", clientId); log.info("客户端ID为:{}", clientId);
// 处理二进制流数据 // 处理二进制流数据
byte[] bytes = new byte[byteBuffer.remaining()]; byte[] bytes = new byte[byteBuffer.remaining()];
//从缓冲区中读取数据并存储到指定的字节数组中 //从缓冲区中读取数据并存储到指定的字节数组中
byteBuffer.get(bytes); byteBuffer.get(bytes);
log.info("2、运行时间:{}",System.currentTimeMillis()/1000);
// 生成唯一文件名 // 生成唯一文件名
String fileName = clientId + "_" + System.currentTimeMillis() + ".webm"; String fileName = clientId + "_" + System.currentTimeMillis() + ".webm";
String pathUrl = RuoYiConfig.getProfile()+VOICE_STORAGE_DIR + fileName; String pathUrl = RuoYiConfig.getProfile()+VOICE_STORAGE_DIR + fileName;
// String pathUrl = "/Users/wangxiangshun/Desktop/0.8733346782733291.webm"; // String pathUrl = "/Users/wangxiangshun/Desktop/0.8733346782733291.webm";
log.info("文件路径为:{}", pathUrl); log.info("文件路径为:{}", pathUrl);
saveAsWebM(bytes, pathUrl); saveAsWebM(bytes, pathUrl);
log.info("3、运行时间:{}",System.currentTimeMillis()/1000);
//拿到文件进行文字转换 //拿到文件进行文字转换
WhisperClient whisperClient = SpringUtils.getBean(WhisperClient.class); WhisperClient whisperClient = SpringUtils.getBean(WhisperClient.class);
String resultText = whisperClient.handleVoiceToText(pathUrl); String resultText = whisperClient.handleVoiceToText(pathUrl);
log.info("4、运行时间:{}",System.currentTimeMillis()/1000);
//把提问的文字发送给CPT //把提问的文字发送给CPT
ChatGPTClient chatGPTClient = SpringUtils.getBean(ChatGPTClient.class); ChatGPTClient chatGPTClient = SpringUtils.getBean(ChatGPTClient.class);
String resultMsg = chatGPTClient.handleAiChat(resultText); String resultMsg = chatGPTClient.handleAiChat(resultText);
log.info("5、运行时间:{}",System.currentTimeMillis()/1000);
//把结果文字转成语音文件 //把结果文字转成语音文件
//生成文件 //生成文件
// 生成唯一文件名 // 生成唯一文件名
@@ -95,6 +100,7 @@ public class ChatWebSocketHandler {
String resultPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + resultFileName; String resultPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + resultFileName;
ElevenLabsClient elevenLabsClient = SpringUtils.getBean(ElevenLabsClient.class); ElevenLabsClient elevenLabsClient = SpringUtils.getBean(ElevenLabsClient.class);
elevenLabsClient.handleTextToVoice(resultMsg, resultPathUrl); elevenLabsClient.handleTextToVoice(resultMsg, resultPathUrl);
log.info("6、运行时间:{}",System.currentTimeMillis()/1000);
//把语音文件转换成流,发送给前端 //把语音文件转换成流,发送给前端
System.out.println("接收到二进制数据,长度: " + bytes.length + " bytes"); System.out.println("接收到二进制数据,长度: " + bytes.length + " bytes");
try { try {
@@ -103,6 +109,7 @@ public class ChatWebSocketHandler {
session.getBasicRemote().sendBinary(outByteBuffer); session.getBasicRemote().sendBinary(outByteBuffer);
// 发送响应确认 // 发送响应确认
session.getBasicRemote().sendText("已收到二进制数据,长度: " + bytes.length); session.getBasicRemote().sendText("已收到二进制数据,长度: " + bytes.length);
log.info("7、运行时间:{}",System.currentTimeMillis()/1000);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }