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