面试流程性能优化处理
This commit is contained in:
@@ -276,6 +276,14 @@ public class ChatWebSocketMultipleHandler {
|
||||
ByteBuffer outByteBuffer = convertFileToByteBuffer(pathUrl);
|
||||
//发送文件流数据
|
||||
session.getBasicRemote().sendBinary(outByteBuffer);
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
}catch (Exception e){}
|
||||
//提示已经结束
|
||||
Map<String,String> dataText = new HashMap<>();
|
||||
dataText.put("type","voiceEnd");
|
||||
dataText.put("content","");
|
||||
session.getBasicRemote().sendText(JSONUtil.toJsonStr(dataText));
|
||||
// 发送响应确认
|
||||
log.info("已经成功发送了语音流给前端:{}", DateUtil.now());
|
||||
} catch (Exception e) {
|
||||
@@ -291,11 +299,10 @@ public class ChatWebSocketMultipleHandler {
|
||||
* @param session 客户端会话ID
|
||||
*/
|
||||
private void sendTTSBuffer(String clientId, String content, Session session) {
|
||||
String resultFileName = clientId + "_" + System.currentTimeMillis() + ".wav";
|
||||
String resultPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + resultFileName;
|
||||
// String resultFileName = clientId + "_" + System.currentTimeMillis() + ".wav";
|
||||
// String resultPathUrl = RuoYiConfig.getProfile() + VOICE_STORAGE_RESULT_DIR + resultFileName;
|
||||
ElevenLabsStreamClient elevenLabsClient = SpringUtils.getBean(ElevenLabsStreamClient.class);
|
||||
elevenLabsClient.handleTextToVoice(content, resultPathUrl,session);
|
||||
|
||||
elevenLabsClient.handleTextToVoice(content,session);
|
||||
//持续返回数据流给客户端
|
||||
log.info("发送语音流成功啦!!!!!!!");
|
||||
// sendVoiceBuffer(resultPathUrl, session);
|
||||
@@ -691,8 +698,13 @@ public class ChatWebSocketMultipleHandler {
|
||||
questionResult = questionResult + content;
|
||||
}
|
||||
cacheQuestionResult.put(session.getId(),questionResult);
|
||||
sendTTSBuffer(clientId,content,session);
|
||||
//上面语音发送完成了,开始发送问题文本啦
|
||||
// 实时输出内容
|
||||
try{
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
}catch (Exception e){}
|
||||
//把文本也给前端返回去
|
||||
Map<String,String> dataText = new HashMap<>();
|
||||
dataText.put("type","question");
|
||||
@@ -701,7 +713,7 @@ public class ChatWebSocketMultipleHandler {
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendTTSBuffer(clientId,content,session);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user