From 61ecfd2d927ca5ca39f11b77237a73e548209eec Mon Sep 17 00:00:00 2001 From: JianYu Zheng <2375294554@qq.com> Date: Mon, 7 Jul 2025 10:58:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=99=BA=E8=83=BD=E4=BD=93?= =?UTF-8?q?=E5=A3=B0=E7=BA=B9=E6=9C=8D=E5=8A=A1=E5=B1=82=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=9A=84=E2=80=98=E8=8E=B7=E5=8F=96=E6=8C=87=E5=AE=9A=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E4=BD=93=E7=9A=84=E6=89=80=E6=9C=89=E5=A3=B0=E7=BA=B9?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E2=80=99=E5=92=8C=E2=80=98=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E4=BD=93=E7=9A=84=E6=8C=87=E7=9A=84=E5=A3=B0?= =?UTF-8?q?=E7=BA=B9=E6=95=B0=E6=8D=AE=E2=80=99=E5=AE=9A=E4=B9=89=EF=BC=88?= =?UTF-8?q?=E6=9C=AA=E6=B5=8B=E8=AF=95=EF=BC=89=20--AgentVoicePrintService?= =?UTF-8?q?Impl.java=20=E5=AE=9E=E7=8E=B0=E6=96=B9=E6=B3=95=20=201.?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=8C=87=E5=AE=9A=E6=99=BA=E8=83=BD=E4=BD=93?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E5=A3=B0=E7=BA=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=20=202.=E6=9B=B4=E6=96=B0=E6=99=BA=E8=83=BD=E4=BD=93=E7=9A=84?= =?UTF-8?q?=E6=8C=87=E7=9A=84=E5=A3=B0=E7=BA=B9=E6=95=B0=E6=8D=AE=20=203.?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=85=B1=E7=94=A8=E6=96=B9=E6=B3=95=EF=BC=88?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=A3=B0=E7=BA=B9=E9=9F=B3=E9=A2=91=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=8F=91=E9=80=81=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E5=A3=B0=E7=BA=B9http=E8=AF=B7=E6=B1=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AgentVoicePrintServiceImpl.java | 122 +++++++++++------- 1 file changed, 77 insertions(+), 45 deletions(-) diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentVoicePrintServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentVoicePrintServiceImpl.java index 974d4aa9..a51067ea 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentVoicePrintServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentVoicePrintServiceImpl.java @@ -1,8 +1,10 @@ package xiaozhi.modules.agent.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.core.io.ByteArrayResource; import org.springframework.http.*; import org.springframework.stereotype.Service; @@ -44,58 +46,18 @@ public class AgentVoicePrintServiceImpl extends ServiceImpl body = new LinkedMultiValueMap<>(); - body.add("speaker_id", entity.getId()); - body.add("file", resource); - - // 创建请求头 - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", getAuthorization(uri)); - headers.setContentType(MediaType.MULTIPART_FORM_DATA); - // 创建请求体 - HttpEntity> requestEntity = new HttpEntity<>(body, headers); - // 发送 POST 请求 - ResponseEntity response = restTemplate.postForEntity(requestUrl, requestEntity, String.class); - - if (response.getStatusCode() != HttpStatus.OK) { - throw new RenException("声纹保存失败"); - } - // 检查响应内容 - String responseBody = response.getBody(); - if(responseBody == null || !responseBody.contains("true")){ - throw new RenException("声纹保存失败"); + return false; } + registerVoicePrint(entity.getId(), resource); return true; } - - @Override public boolean delete(String voicePrintId) { int insert = baseMapper.deleteById(voicePrintId); @@ -126,12 +88,27 @@ public class AgentVoicePrintServiceImpl extends ServiceImpl list(String agentId) { - return List.of(); + List list = baseMapper.selectList(new LambdaQueryWrapper() + .eq(AgentVoicePrintEntity::getAgentId, agentId)); + return list.stream().map(entity -> { + // 遍历转换成AgentVoicePrintVO类型 + return ConvertUtils.sourceToTarget(entity, AgentVoicePrintVO.class); + }).toList(); + } @Override public boolean update(AgentVoicePrintUpdateDTO dto) { - return false; + // 获取音频Id + String audioId = dto.getAudioId(); + // 如果有新的音频,则注册新的声纹 + if (!StringUtils.isEmpty(audioId)) { + ByteArrayResource resource = getVoicePrintAudioWAV(audioId); + registerVoicePrint(dto.getId(),resource); + } + AgentVoicePrintEntity entity = ConvertUtils.sourceToTarget(dto, AgentVoicePrintEntity.class); + baseMapper.updateById(entity); + return true; } /** @@ -175,4 +152,59 @@ public class AgentVoicePrintServiceImpl extends ServiceImpl body = new LinkedMultiValueMap<>(); + body.add("speaker_id", id); + body.add("file", resource); + + // 创建请求头 + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", getAuthorization(uri)); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + // 创建请求体 + HttpEntity> requestEntity = new HttpEntity<>(body, headers); + // 发送 POST 请求 + ResponseEntity response = restTemplate.postForEntity(requestUrl, requestEntity, String.class); + + if (response.getStatusCode() != HttpStatus.OK) { + throw new RenException("声纹保存失败"); + } + // 检查响应内容 + String responseBody = response.getBody(); + if(responseBody == null || !responseBody.contains("true")){ + throw new RenException("声纹保存失败"); + } + } }