STT 数据流处理

This commit is contained in:
2025-10-20 15:09:05 +08:00
parent c806410d41
commit 775bd96417

View File

@@ -115,29 +115,29 @@ public class ChatWebSocketHandler {
String resultFlag = mapResult.get("msg"); String resultFlag = mapResult.get("msg");
if("done".equals(resultFlag)){ if("done".equals(resultFlag)){
log.info("1、开始处理时间:{}",System.currentTimeMillis()/1000); log.info("1、开始处理时间:{}",System.currentTimeMillis()/1000);
//开始合并语音流 // //开始合并语音流
List<byte[]> fragments = fragmentCache.get(clientId); // List<byte[]> fragments = fragmentCache.get(clientId);
// 合并所有分片为完整语音数据 // // 合并所有分片为完整语音数据
byte[] fullVoiceData = mergeFragments(fragments); // byte[] fullVoiceData = mergeFragments(fragments);
// 生成唯一文件名 // // 生成唯一文件名
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;
log.info("文件路径为:{}", pathUrl); // log.info("文件路径为:{}", pathUrl);
log.info("文件流的大小为:{}",fullVoiceData.length); // log.info("文件流的大小为:{}",fullVoiceData.length);
saveAsWebM(fullVoiceData,pathUrl); // saveAsWebM(fullVoiceData,pathUrl);
//开始转换 // //开始转换
WhisperClient whisperClient = SpringUtils.getBean(WhisperClient.class); // WhisperClient whisperClient = SpringUtils.getBean(WhisperClient.class);
String cacheResultText = whisperClient.handleVoiceToText(pathUrl); // String cacheResultText = whisperClient.handleVoiceToText(pathUrl);
//发送消息 //发送消息
// WebSocket webSocket = cacheWebSocket.get(clientId); WebSocket webSocket = cacheWebSocket.get(clientId);
// webSocket.send("{\"type\": \"input_audio_buffer.commit\"}"); webSocket.send("{\"type\": \"input_audio_buffer.commit\"}");
// webSocket.send("{\"type\": \"response.create\"}"); webSocket.send("{\"type\": \"response.create\"}");
// if(webSocket != null){ // if(webSocket != null){
// webSocket.close(1000,null); // webSocket.close(1000,null);
// } // }
//语音结束,开始进行回答解析 //语音结束,开始进行回答解析
// String cacheResultText = cacheClientTts.get(clientId); String cacheResultText = cacheClientTts.get(clientId);
log.info("返回的结果为:{}",cacheResultText); log.info("返回的结果为:{}",cacheResultText);
if(StrUtil.isEmpty(cacheResultText)){ if(StrUtil.isEmpty(cacheResultText)){
cacheResultText = "Hello , How are you?"; cacheResultText = "Hello , How are you?";