2 Commits

Author SHA1 Message Date
zhaoyf
bced456945 opt:语音控制功能-第一次联调测试修改 2026-04-22 10:47:24 +08:00
zhaoyf
5d83cceca5 opt:语音控制功能-添加vc回调接口 2026-04-20 10:12:55 +08:00
13 changed files with 542 additions and 111 deletions

View File

@@ -35,6 +35,9 @@
<if test="pcsn != null and pcsn != ''">
AND gro.pcsn = #{pcsn}
</if>
<if test="struct_code != null and struct_code != ''">
AND ivt.struct_code = #{struct_code}
</if>
<if test="stor_code != null and stor_code != ''">
AND ivt.stor_code = #{stor_code}
</if>

View File

@@ -16,7 +16,7 @@ import java.util.Map;
*/
@Slf4j
@RestController
@RequestMapping("/speech")
@RequestMapping("/api/speech")
public class SysSpeechController {
@Resource
@@ -56,7 +56,7 @@ public class SysSpeechController {
*/
@PostMapping("/confirm")
public ResponseEntity<Object> confirm(@RequestBody Map<String, Object> body){
sysSpeechService.confirm(body.getOrDefault("text","").toString());
return new ResponseEntity<>(HttpStatus.OK);
Map<String, Object> res = sysSpeechService.confirm(body.getOrDefault("text", "").toString());
return ResponseEntity.ok(res);
}
}

View File

@@ -56,46 +56,42 @@ public class SysSpeechWebSocketEndpoint {
if ("start".equals(type)) {
//TODO 健康检查
asrTtsClient.health().thenAccept(result -> {
log.info("健康检查结果: {}", result);
Integer resCode = JSON.parseObject(result.toString()).getInteger("code");
if (resCode != 0) {
sendError("语音控制服务异常");
sendTextBySys("语音控制服务异常");
}
}).exceptionally(ex -> {
log.error("健康检查异常: {}", session.getId(), ex);
sendError("语音控制服务异常");
sendTextBySys("语音控制服务异常");
return null;
});
} else if ("end".equals(type)) {
// 录音结束,将 PCM 数据发送给第三方 ASR
byte[] pcmData = ctx.audioBuffer.toByteArray();
//测试
// String resp = JSONObject.toJSONString(MapOf.of("type", "transcription", "text", "识别结果"));
// String resp1 = JSONObject.toJSONString(MapOf.of("type", "response", "text", "系统回复消息"));
// session.getBasicRemote().sendText(resp);
// session.getBasicRemote().sendText(resp1);
//测试结束
// 异步调用第三方服务,避免阻塞 WebSocket 线程
asrTtsClient.recognizeAsync(pcmData, ctx.sampleRate, ctx.channels, ctx.bitDepth)
.thenAccept(result -> {
JSONObject jsonObject = JSON.parseObject(result.toString(), JSONObject.class);
log.info("ASR 输出参数为:-------------------" + jsonObject.toString());
Integer code = jsonObject.getInteger("code");
if (code == null || code != 0) {
String msg = jsonObject.getString("msg");
sendError(msg != null ? msg : "未知错误");
sendTextBySys(msg != null ? msg : "未知错误");
return;
}
JSONObject data = jsonObject.getJSONObject("data");
if (data != null) {
String text = data.getString("text");
sendText(text);
sendTextByUser(text);
} else {
sendError("语音转文字发生错误");
sendTextBySys("语音转文字发生错误");
}
})
.exceptionally(ex -> {
log.error("ASR 异常: {}", session.getId(), ex);
sendError("ASR 异常");
sendTextByUser("ASR 异常");
return null;
});
ctx.audioBuffer.reset();
@@ -144,11 +140,11 @@ public class SysSpeechWebSocketEndpoint {
}
}
private void sendText(String message) {
private void sendTextByUser(String message) {
try {
Map<String, Object> map = new HashMap<>();
map.put("type", "result");
map.put("text", message);
map.put("type", "user");
map.put("message", message);
// 结果通过 WebSocket 返回给前端
String response = objectMapper.writeValueAsString(map);
session.getBasicRemote().sendText(response);
@@ -157,10 +153,10 @@ public class SysSpeechWebSocketEndpoint {
}
}
private void sendError(String message) {
private void sendTextBySys(String message) {
try {
Map<String, String> map = new HashMap<>();
map.put("type", "error");
map.put("type", "system");
map.put("message", message);
session.getBasicRemote().sendText(
objectMapper.writeValueAsString(map));

View File

@@ -0,0 +1,74 @@
package org.nl.wms.system_manage.controller.speech;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.exception.BadRequestException;
import org.nl.wms.system_manage.service.speech.VoiceCallbackService;
import org.nl.wms.system_manage.service.speech.dto.InboundTaskRequest;
import org.nl.wms.system_manage.service.speech.dto.MoveTaskRequest;
import org.nl.wms.system_manage.service.speech.dto.OutboundTaskRequest;
import org.nl.wms.system_manage.service.speech.dto.QueryBoundRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
* vc回调接口
*/
@RestController
@RequestMapping("/api/wms/task")
@Slf4j
public class VoiceCallbackController {
@Autowired
private VoiceCallbackService voiceCallbackService;
/**
* 语音语义解析后异步调用的任务生成接口
*/
@PostMapping("/generate")
@SaIgnore
public ResponseEntity<Object> generate(@RequestBody JSONObject voiceDto) {
System.out.println("接收任务" + JSON.toJSONString(voiceDto));
String commandType = voiceDto.getString("commandType");
JSONObject commandParam = voiceDto.getJSONObject("commandParam");
JSONObject result;
switch (commandType) {
case "taskIssue":
final String taskType = commandParam.getString("taskType");
switch (taskType) {
case "inbound":
InboundTaskRequest inboundRequest = JSON.toJavaObject(commandParam, InboundTaskRequest.class);
result = voiceCallbackService.handleInboundTask(inboundRequest);
break;
case "move":
MoveTaskRequest moveRequest = JSON.toJavaObject(commandParam, MoveTaskRequest.class);
result = voiceCallbackService.handleMoveTask(moveRequest);
break;
case "outbound":
OutboundTaskRequest outboundRequest = JSON.toJavaObject(commandParam, OutboundTaskRequest.class);
result = voiceCallbackService.handleOutboundTask(outboundRequest);
break;
default:
throw new BadRequestException("未知的指令类型: " + commandType);
}
break;
case "InventoryQuery":
QueryBoundRequest queryRequest = JSON.toJavaObject(commandParam, QueryBoundRequest.class);
result = voiceCallbackService.handleQueryTask(queryRequest);
break;
default:
throw new BadRequestException("未知的指令类型: " + commandType);
}
return new ResponseEntity<>(result, HttpStatus.OK);
}
}

View File

@@ -0,0 +1,262 @@
package org.nl.wms.system_manage.service.speech;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.SpringContextHolder;
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
import org.nl.wms.basedata_manage.service.IStructattrService;
import org.nl.wms.basedata_manage.service.dao.*;
import org.nl.wms.basedata_manage.service.dto.StrategyMater;
import org.nl.wms.basedata_manage.service.dto.StrategyStructMaterialVO;
import org.nl.wms.basedata_manage.service.dto.StrategyStructParam;
import org.nl.wms.pda_manage.ios_manage.service.PdaIosInService;
import org.nl.wms.pda_manage.ios_manage.service.PdaIosOutService;
import org.nl.wms.sch_manage.enums.StatusEnum;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.tasks.StInTask;
import org.nl.wms.sch_manage.service.util.tasks.VehicleOutTask;
import org.nl.wms.system_manage.service.speech.dto.InboundTaskRequest;
import org.nl.wms.system_manage.service.speech.dto.MoveTaskRequest;
import org.nl.wms.system_manage.service.speech.dto.OutboundTaskRequest;
import org.nl.wms.system_manage.service.speech.dto.QueryBoundRequest;
import org.nl.wms.warehouse_manage.enums.IOSConstant;
import org.nl.wms.warehouse_manage.enums.IOSEnum;
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateService;
import org.nl.wms.warehouse_manage.service.IStIvtMoveinvService;
import org.nl.wms.warehouse_manage.service.dao.GroupPlate;
import org.nl.wms.warehouse_manage.service.dto.MoveInsertDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.nl.wms.warehouse_manage.enums.IOSEnum.GROUP_PLATE_STATUS;
@Slf4j
@Service
public class VoiceCallbackService {
@Autowired
private IStructattrService iStructattrService;
@Resource
private Map<String, AbstractTask> applyTaskMap;
@Autowired
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
@Autowired
private ISchBasePointService iSchBasePointService;
@Autowired
private IMdPbGroupplateService iMdPbGroupplateService;
@Transactional
public JSONObject handleInboundTask(InboundTaskRequest inboundTaskRequest){
// SchBasePoint one = iSchBasePointService.getOne(new LambdaQueryWrapper<SchBasePoint>()
// .eq(SchBasePoint::getPoint_code, inboundTaskRequest.getLocationFrom()));
SchBasePoint one = iSchBasePointService.getOne(new LambdaQueryWrapper<SchBasePoint>()
.eq(SchBasePoint::getPoint_code, "RKD01"));
//分配仓位
MdMeMaterialbase meMaterialbase = iMdMeMaterialbaseService.getByCode(inboundTaskRequest.getMaterial());
GroupPlate groupDao = GroupPlate.builder()
.group_id(IdUtil.getStringId())
.material_id(meMaterialbase.getMaterial_id())
.storagevehicle_code(one.getVehicle_code())
.pcsn("111")
.qty_unit_id(meMaterialbase.getQty_unit_id())
.qty_unit_name(meMaterialbase.getQty_unit_name())
.qty(new BigDecimal(inboundTaskRequest.getQty()))
.status(GROUP_PLATE_STATUS.code("组盘"))
.create_id(SecurityUtils.getCurrentUserId())
.create_name(SecurityUtils.getCurrentNickName())
.create_time(DateUtil.now())
.build();
iMdPbGroupplateService.save(groupDao);
StrategyMater mater = new StrategyMater();
mater.setMaterial_code(inboundTaskRequest.getMaterial());
mater.setMaterial_id(meMaterialbase.getMaterial_id());
mater.setQty(new BigDecimal(inboundTaskRequest.getQty()));
mater.setPcsn("111");
List<StrategyMater> materss = new ArrayList<>();
materss.add(mater);
List<Structattr> structattrs = iStructattrService.inBoundSectDiv(
StrategyStructParam.builder()
.ioType(StatusEnum.STRATEGY_TYPE.code("入库"))
.sect_code("YL01")
.stor_code("YL")
.storagevehicle_code(one.getVehicle_code())
.strategyMaters(materss)
.build());
if (CollectionUtils.isEmpty(structattrs)) {
throw new BadRequestException("无可用货位");
}
Structattr attrDao = structattrs.get(0);
//确定起点
// SchBasePoint schBasePoint = iSchBasePointService.getOne(new LambdaQueryWrapper<SchBasePoint>()
// .eq(SchBasePoint::getPoint_code, inboundTaskRequest.getLocationFrom()));
// if (ObjectUtil.isEmpty(schBasePoint)) {
// throw new BadRequestException("未找到载具所在的点位信息,请检查");
// }
JSONObject whereJson = new JSONObject();
// whereJson.put("point_code1", "RKD01");
// whereJson.put("point_code1", schBasePoint.getPoint_code());
//确定终点
// whereJson.put("point_code2", attrDao.getStruct_code());
whereJson.put("vehicle_code", one.getVehicle_code());
whereJson.put("task_type", "STInTask");
whereJson.put("TaskCode", CodeUtil.getNewCode("TASK_CODE"));
whereJson.put("PickingLocation", "RKD01");
whereJson.put("PlacedLocation", attrDao.getStruct_code());
//创建任务
String taskId = applyTaskMap.get("STInTask").create(whereJson);
// 更新起点绑定id
iSchBasePointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getIos_id, null)
.eq(SchBasePoint::getPoint_code, "RKD01")
);
// 更新终点锁定状态
JSONObject lock_map = new JSONObject();
lock_map.put("struct_code", attrDao.getStruct_code());
lock_map.put("inv_id", null);
lock_map.put("inv_code", null);
lock_map.put("inv_type", null);
lock_map.put("taskdtl_id", taskId);
lock_map.put("lock_type", IOSEnum.LOCK_TYPE.code("入库锁"));
iStructattrService.updateStatusByCode("0", lock_map);
return null;
};
@Transactional
public JSONObject handleOutboundTask(OutboundTaskRequest outboundTaskRequest){
MdMeMaterialbase meMaterialbase = iMdMeMaterialbaseService.getByCode(outboundTaskRequest.getMaterial());
JSONObject whereJson = new JSONObject();
whereJson.put("material_id", meMaterialbase.getMaterial_id());
whereJson.put("material_code", meMaterialbase.getMaterial_code());
whereJson.put("stor_code", "YL");
whereJson.put("sect_code", "YL01");
whereJson.put("siteCode", "CKD01");
StrategyMater mater = new StrategyMater();
mater.setQty(BigDecimal.valueOf(outboundTaskRequest.getQty()));
mater.setMaterial_id(meMaterialbase.getMaterial_id());
mater.setMaterial_code(meMaterialbase.getMaterial_code());
List<StrategyMater> maters = new ArrayList<>();
maters.add(mater);
StrategyStructParam strategyStructParam = StrategyStructParam.builder()
.ioType(whereJson.getString(StatusEnum.STRATEGY_TYPE.code("出库")))
.sect_code(whereJson.getString("sect_code"))
.stor_code(whereJson.getString("stor_code"))
.strategyMaters(maters)
.build();
List<StrategyStructMaterialVO> structList = iStructattrService.outBoundSectDiv(strategyStructParam);
if (CollectionUtils.isEmpty(structList)) {
throw new BadRequestException("无可用库存!");
}
structList.forEach(r -> {
//创建任务
JSONObject taskForm = new JSONObject();
taskForm.put("task_type", IOSConstant.VEHICLE_OUT_TASK);
taskForm.put("config_code", IOSConstant.VEHICLE_OUT_TASK);
taskForm.put("TaskCode", CodeUtil.getNewCode("TASK_CODE"));
taskForm.put("PickingLocation", r.getStruct_code());
taskForm.put("PlacedLocation", whereJson.getString("siteCode"));
taskForm.put("vehicle_code", r.getStoragevehicle_code());
applyTaskMap.get(IOSConstant.VEHICLE_OUT_TASK).create(taskForm);
});
//更新组盘记录表
Set<String> vehicleCodeSet = structList.stream()
.map(StrategyStructMaterialVO::getStoragevehicle_code)
.collect(Collectors.toSet());
iMdPbGroupplateService.update(
new GroupPlate(),
new LambdaUpdateWrapper<GroupPlate>()
.set(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("出库"))
.in(GroupPlate::getStoragevehicle_code, vehicleCodeSet)
);
//锁定仓位
Set<String> structCodeSet = structList.stream()
.map(StrategyStructMaterialVO::getStruct_code)
.collect(Collectors.toSet());
iStructattrService.update(
new LambdaUpdateWrapper<Structattr>()
.set(Structattr::getInv_id, null)
.set(Structattr::getInv_code, null)
.set(Structattr::getInv_type, null)
.set(Structattr::getLock_type, IOSEnum.LOCK_TYPE.code("出库锁"))
.in(Structattr::getStruct_code, structCodeSet)
);
return null;
};
public JSONObject handleMoveTask(MoveTaskRequest moveTaskRequest){
Structattr attrDao = iStructattrService.findByCode(moveTaskRequest.getLocationFrom());
JSONObject taskForm = new JSONObject();
taskForm.put("point_code1", moveTaskRequest.getLocationFrom());
taskForm.put("point_code", moveTaskRequest.getLocationTo());
taskForm.put("config_code", IOSConstant.MOVE_CONFIG_TASK);
taskForm.put("vehicle_code", attrDao.getStoragevehicle_code());
String taskId = applyTaskMap.get("MoveTask").create((JSONObject) JSONObject.toJSON(taskForm));
return null;
};
public JSONObject handleQueryTask(QueryBoundRequest queryBoundRequest){
List<StructattrVechielDto> structCode = iStructattrService.collectVechicle(MapOf.of("struct_code", queryBoundRequest.getLocation(), "search", queryBoundRequest.getMaterial()));
Map<String, BigDecimal> collect = structCode.stream()
.collect(Collectors.groupingBy(StructattrVechielDto::getMaterial_code,
Collectors.reducing(BigDecimal.ZERO, StructattrVechielDto::getQty, BigDecimal::add)));
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("当前仓库物料有物料");
collect.entrySet().forEach(r -> {
stringBuffer.append(r.getKey()).append("共计")
.append(r.getValue())
.append("");
});
// for (StructattrVechielDto vechielDtos : structCode) {
// stringBuffer.append(vechielDtos.getMaterial_name()).append("共计")
// .append(vechielDtos.getQty())
// .append("个");
// }
String text = stringBuffer.toString();
try {
// voiceService.speechTts(text);
}catch (Exception ex){
ex.printStackTrace();
}
JSONObject result = new JSONObject();
result.put("has",text);
return result ;
};
}

View File

@@ -18,6 +18,7 @@ public class AsrTtsClient {
@Value("${vc.base-url:http://127.0.0.1:5000}")
private String vcBaseUrl;
/**
* 健康检查
*/
@@ -29,12 +30,14 @@ public class AsrTtsClient {
});
}
/**
* 语音转文字
*/
public static void asr() {
}
/**
* 文字转语音
*/
@@ -55,11 +58,11 @@ public class AsrTtsClient {
});
}
/**
* 用户确认文字
*/
public CompletableFuture<Object> confirm(String text, boolean confirmed) {
return CompletableFuture.supplyAsync(() -> {
public String confirm(String text, boolean confirmed) {
Map<String, Object> params = new HashMap<>();
params.put("text", text);
params.put("confirmed", confirmed);
@@ -68,7 +71,6 @@ public class AsrTtsClient {
.contentType("application/json")
.execute()
.body();
});
}
@@ -76,7 +78,8 @@ public class AsrTtsClient {
return CompletableFuture.supplyAsync(() -> {
return HttpRequest.post(vcBaseUrl + "/api/speech/asr")
.form("audio", pcmData)
.form("audio", pcmData, "audio.pcm")
// .body(pcmData)
.contentType("multipart/form-data")
.execute()
.body();

View File

@@ -0,0 +1,19 @@
package org.nl.wms.system_manage.service.speech.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class InboundTaskRequest {
@JsonProperty("commandType")
private String commandType; // 指令类型taskIssue
@JsonProperty("deviceId")
private String deviceId; // 语音设备ID
@JsonProperty("taskType")
private String taskType; // 任务类型inbound
@JsonProperty("locationFrom")
private String locationFrom; // 取货点编号:从哪个位置入库
@JsonProperty("material")
private String material; // 物料编码
@JsonProperty("qty")
private Integer qty; // 入库物料数量
}

View File

@@ -0,0 +1,17 @@
package org.nl.wms.system_manage.service.speech.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class MoveTaskRequest {
@JsonProperty("commandType")
private String commandType; // 指令类型taskIssue
@JsonProperty("deviceId")
private String deviceId; // 语音设备ID
@JsonProperty("taskType")
private String taskType; // 任务类型move
@JsonProperty("locationFrom")
private String locationFrom; // 取货点编号:从哪个库位取货
@JsonProperty("locationTo")
private String locationTo; // 放货点编号:移到哪个库位
}

View File

@@ -0,0 +1,17 @@
package org.nl.wms.system_manage.service.speech.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class OutboundTaskRequest {
@JsonProperty("commandType")
private String commandType; // 指令类型taskIssue
@JsonProperty("deviceId")
private String deviceId; // 语音设备ID
@JsonProperty("taskType")
private String taskType; // 任务类型outbound
@JsonProperty("material")
private String material; // 物料编码:需要出什么料
@JsonProperty("qty")
private Integer qty; // 出库数量
}

View File

@@ -0,0 +1,15 @@
package org.nl.wms.system_manage.service.speech.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class QueryBoundRequest {
@JsonProperty("commandType")
private String commandType; // 指令类型InventoryQuery
@JsonProperty("deviceId")
private String deviceId; // 语音设备ID
@JsonProperty("location")
private String location; // 货位编号:基于货位查看库存
@JsonProperty("material")
private String material; // 物料编码:基于物料查询库存
}

View File

@@ -1,5 +1,6 @@
package org.nl.wms.system_manage.service.speech.impl;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.utils.MapOf;
import org.nl.wms.system_manage.service.speech.SysSpeechService;
@@ -42,15 +43,17 @@ public class SysSpeechServiceImpl implements SysSpeechService {
if ("".equals(text)) {
throw new RuntimeException("确认文本为空");
}
asrTtsClient.confirm(text, true)
.thenAccept(result -> {
log.info("语音控制:用户确认结果: {}", result);
}).exceptionally(ex -> {
log.error("语音控制:用户确认异常: {}", ex);
return null;
});
String resJson = asrTtsClient.confirm(text, true);
log.info("语音控制:用户确认结果: {}", resJson);
//TODO
JSONObject jsonObject = JSONObject.parseObject(resJson);
JSONObject data = jsonObject.getJSONObject("data");
if (data != null) {
String resText = data.getString("text");
return MapOf.of("text", resText);
}
byte[] audio = asrTtsClient.tts(text).join();
//TODO 音频返回前端播放处理
return Collections.emptyMap();
return MapOf.of("text", text);
}
}

View File

@@ -9,10 +9,11 @@ spring:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${DB_HOST:192.168.81.251}:${DB_PORT:3306}/${DB_NAME:wms_standardv2}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
# url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:wms_oulun}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
# url: jdbc:mysql://${DB_HOST:192.168.81.251}:${DB_PORT:3306}/${DB_NAME:wms_standardv2}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:wms_standardv2}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
username: ${DB_USER:root}
password: ${DB_PWD:P@ssw0rd.}
password: ${DB_PWD:123456}
# password: ${DB_PWD:P@ssw0rd.}
# 初始连接数
initial-size: 15
# 最小连接数
@@ -137,3 +138,5 @@ sa-token:
lucene:
index:
path: D:\lms\lucene\index
vc:
base-url: http://192.168.20.156:5000

View File

@@ -133,10 +133,18 @@
<span>正在录音... {{ recordingDuration }}"</span>
</div>
<!-- 识别中提示 -->
<div v-if="isTranscribing" class="transcribing-hint">
<div class="transcribing-spinner">
<i class="el-icon-loading" />
</div>
<span>正在识别录音内容...</span>
</div>
<!-- 录音按钮 -->
<div
class="record-button"
:class="{ 'recording': isRecording, 'disabled': !isConnected || isProcessing }"
:class="{ 'recording': isRecording, 'disabled': !isConnected || isProcessing || isTranscribing }"
@mousedown="startRecording"
@mouseup="stopRecording"
@mouseleave="isRecording && stopRecording()"
@@ -240,7 +248,7 @@ export default {
this.isConnected = false
},
// 处理WebSocket消息
// 处理WebSocket消息 - 只处理user和system两种类型
handleWebSocketMessage(data) {
// 判断数据类型
if (data instanceof ArrayBuffer || data instanceof Blob) {
@@ -252,14 +260,21 @@ export default {
const message = JSON.parse(data)
console.log('收到WebSocket消息:', message)
if (message.type === 'error') {
this.handleError(message.message || '识别失败')
} else if (message.type === 'transcription') {
// 语音识别结果
this.handleTranscriptionResult(message)
} else if (message.type === 'response') {
// 系统文本回复
this.handleSystemTextResponse(message)
// 只处理user和system两种类型
if (message.type === 'user') {
// 用户识别结果消息
this.handleUserMessage(message)
} else if (message.type === 'system') {
// 系统回复消息
this.handleSystemMessage(message)
} else if (message.type === 'error') {
// 错误消息作为系统消息显示
this.addMessage({
role: 'system',
type: 'text',
content: message.message || '处理失败',
timestamp: Date.now()
})
}
} catch (e) {
console.error('解析WebSocket消息失败:', e)
@@ -267,9 +282,9 @@ export default {
}
},
// 处理语音识别结果
handleTranscriptionResult(message) {
const text = message.text || message.transcript || ''
// 处理用户消息(语音识别结果
handleUserMessage(message) {
const text = message.message
if (!text) return
this.isTranscribing = false
@@ -284,6 +299,19 @@ export default {
})
},
// 处理系统消息
handleSystemMessage(message) {
this.isProcessing = false
// 添加系统消息
this.addMessage({
role: 'system',
type: 'text',
content: message.message,
timestamp: Date.now()
})
},
// 确认消息 - 用户点击确认按钮后执行
async confirmMessage(message) {
if (!message || !message.content) return
@@ -294,14 +322,16 @@ export default {
// 执行confirm函数
try {
const res = await confirm(message.content)
const res = await confirm({
text: message.content
})
this.isProcessing = false
// 添加系统回复消息
this.addMessage({
role: 'system',
type: 'text',
content: res.data || '收到您的消息',
content: res.text,
timestamp: Date.now()
})
} catch (error) {
@@ -328,18 +358,7 @@ export default {
this.scrollToBottom()
},
// 处理系统文本回复
handleSystemTextResponse(message) {
this.isProcessing = false
this.addMessage({
role: 'system',
type: 'text',
content: message.text || message.content || '收到您的消息',
timestamp: Date.now()
})
},
// 处理系统语音回复
// 处理系统语音回复(二进制数据)
async handleSystemVoiceResponse(audioData) {
try {
// 创建音频URL
@@ -360,7 +379,7 @@ export default {
role: 'system',
type: 'voice',
audioUrl: audioUrl,
duration: '3"', // 这里应该根据实际音频时长计算
duration: '3"',
timestamp: Date.now()
}
this.addMessage(message)
@@ -372,27 +391,7 @@ export default {
}
},
// 处理错误
handleError(message) {
this.isProcessing = false
this.isTranscribing = false
this.addMessage({
role: 'system',
type: 'text',
content: message || '服务出现错误',
timestamp: Date.now()
})
// 更新最后一条用户消息状态
// const lastUserMessage = this.messages.filter(m => m.role === 'user').pop()
// if (lastUserMessage) {
// lastUserMessage.isTranscribing = false
// lastUserMessage.content = message
// lastUserMessage.type = 'text'
// }
//
// this.$message.error(message)
},
// 添加消息
addMessage(message) {
@@ -1030,6 +1029,26 @@ export default {
}
}
.transcribing-hint {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 10px;
color: #409EFF;
font-size: 14px;
.transcribing-spinner {
display: flex;
align-items: center;
margin-right: 8px;
i {
font-size: 18px;
animation: rotating 1s linear infinite;
}
}
}
.record-button {
display: flex;
align-items: center;