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