demo修改

This commit is contained in:
2025-11-03 11:04:42 +08:00
parent 909b874aca
commit d7736a3b2d
3 changed files with 48 additions and 31 deletions

View File

@@ -7,9 +7,7 @@ import com.vetti.common.ai.elevenLabs.ElevenLabsClient;
import com.vetti.common.ai.gpt.ChatGPTClient;
import com.vetti.common.ai.gpt.OpenAiStreamClient;
import com.vetti.common.ai.gpt.service.OpenAiStreamListenerService;
import com.vetti.common.ai.whisper.WhisperClient;
import com.vetti.common.config.RuoYiConfig;
import com.vetti.common.core.redis.RedisCache;
import com.vetti.common.utils.spring.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
@@ -22,11 +20,15 @@ import javax.sound.sampled.AudioSystem;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* 语音面试 web处理器
@@ -73,6 +75,8 @@ public class ChatWebSocketHandler {
*/
private final Map<String,String> cacheQuestionResult = new ConcurrentHashMap<>();
// private final Map<String,String> cacheOpeningResult = new ConcurrentHashMap<>();
// 语音文件保存目录
private static final String VOICE_STORAGE_DIR = "/voice_files/";
@@ -109,19 +113,23 @@ public class ChatWebSocketHandler {
cacheMsgMapData.put(session.getId(),"");
//初始化面试问题
cacheQuestionResult.put(session.getId(),"");
//发送初始化面试官语音流
String openingPathUrl = RuoYiConfig.getProfile() + VOICE_SYSTEM_DIR + "opening.wav";
try {
//文件转换成文件
ByteBuffer outByteBuffer = convertFileToByteBuffer(openingPathUrl);
//发送文件流数据
session.getBasicRemote().sendBinary(outByteBuffer);
// 发送响应确认
log.info("初始化返回面试官语音信息:{}", System.currentTimeMillis() / 1000);
} catch (IOException e) {
e.printStackTrace();
}
//开场白控制
// String flag = cacheOpeningResult.get(clientId);
// if(StrUtil.isEmpty(flag)){
//发送初始化面试官语音
String openingPathUrl = RuoYiConfig.getProfile() + VOICE_SYSTEM_DIR + "opening.wav";
try {
//文件转换成文件流
ByteBuffer outByteBuffer = convertFileToByteBuffer(openingPathUrl);
//发送文件流数据
session.getBasicRemote().sendBinary(outByteBuffer);
// cacheOpeningResult.put(clientId,"YES");
// 发送响应确认
log.info("初始化返回面试官语音信息:{}", System.currentTimeMillis() / 1000);
} catch (IOException e) {
e.printStackTrace();
}
// }
}
// 接收文本消息
@@ -274,6 +282,7 @@ public class ChatWebSocketHandler {
}
});
}else if("end".equals(resultFlag)){
// cacheOpeningResult.put(clientId,"");
//发送面试官结束语音流
String openingPathUrl = RuoYiConfig.getProfile() + VOICE_SYSTEM_DIR + "end.wav";
try {
@@ -297,7 +306,7 @@ public class ChatWebSocketHandler {
Map<String,String> mapEntity = list.get(0);
//更新问题记录
mapEntity.put("role","system");
mapEntity.put("content","你是建筑行业面试专家对Construction Labourer候选人回答进行1-5分评分。");
mapEntity.put("content","You are a construction industry interview expert. Rate Construction Labourer candidate responses on a 1-5 scale. IMPORTANT: If the answer is completely unrelated, contains technical errors, system messages, or is nonsensical, give it a score of 0/5 and explain why it's invalid.");
promptJson = JSONUtil.toJsonStr(list);
//结束回答要清空问答数据
cacheMsgMapData.put(session.getId(),"");
@@ -363,10 +372,10 @@ public class ChatWebSocketHandler {
@OnClose
public void onClose(Session session, CloseReason reason) {
System.out.println("WebSocket连接已关闭: " + session.getId() + ", 原因: " + reason.getReasonPhrase());
WebSocket webSocket = cacheWebSocket.get(session.getId());
if (webSocket != null) {
webSocket.close(1000, null);
}
// WebSocket webSocket = cacheWebSocket.get(session.getId());
// if (webSocket != null) {
// webSocket.close(1000, null);
// }
}
// 发生错误时调用

View File

@@ -39,7 +39,6 @@ public class HotakeSysFileController extends BaseController {
* 查询文件管理列表
*/
@ApiOperation("查询文件管理列表")
@PreAuthorize("@ss.hasPermi('command:sysFile:list')")
@GetMapping("/list")
public TableDataInfo list(HotakeSysFile HotakeSysFile) {
startPage();
@@ -51,7 +50,6 @@ public class HotakeSysFileController extends BaseController {
* 导出文件管理列表
*/
@ApiOperation("导出文件管理列表")
@PreAuthorize("@ss.hasPermi('command:sysFile:export')")
@Log(title = "文件管理", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(HotakeSysFile HotakeSysFile) {
@@ -64,7 +62,6 @@ public class HotakeSysFileController extends BaseController {
* 获取文件管理详细信息
*/
@ApiOperation("获取文件管理详细信息")
@PreAuthorize("@ss.hasPermi('command:sysFile:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(hotakeSysFileService.selectHotakeSysFileById(id));
@@ -74,7 +71,6 @@ public class HotakeSysFileController extends BaseController {
* 新增文件管理
*/
@ApiOperation("新增文件管理")
@PreAuthorize("@ss.hasPermi('command:sysFile:add')")
@Log(title = "文件管理", businessType = BusinessType.INSERT)
@PostMapping
public R<HotakeSysFile> add(@RequestPart("file") MultipartFile file, HotakeSysFileVo fileVo) {
@@ -86,7 +82,6 @@ public class HotakeSysFileController extends BaseController {
* 修改文件管理
*/
@ApiOperation("修改文件管理")
@PreAuthorize("@ss.hasPermi('command:sysFile:edit')")
@Log(title = "文件管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestPart(name = "file", required = false) MultipartFile file, HotakeSysFile HotakeSysFile) {
@@ -97,7 +92,6 @@ public class HotakeSysFileController extends BaseController {
* 删除文件管理
*/
@ApiOperation("删除文件管理")
@PreAuthorize("@ss.hasPermi('command:sysFile:remove')")
@Log(title = "文件管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
@@ -105,7 +99,6 @@ public class HotakeSysFileController extends BaseController {
}
@ApiOperation("禁用文件管理")
@PreAuthorize("@ss.hasPermi('command:sysFile:edit')")
@Log(title = "文件管理", businessType = BusinessType.UPDATE)
@PutMapping("/available/{id}")
public AjaxResult availableSysFile(@PathVariable Long id) {