From 8e909e1fde8af8523c02030d097f1d6b6ed4362a Mon Sep 17 00:00:00 2001 From: daixiaoyi Date: Mon, 10 Mar 2025 09:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=88=A4=E6=96=AD=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E6=97=B6=E9=97=B4=E7=BB=93=E6=9D=9F=E6=97=B6TTS?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9C=89=E8=BF=94=E5=9B=9Eaudio=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=EF=BC=8C=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E5=86=8D=E6=AC=A1=E6=8E=A8=E9=80=81=E9=A2=84?= =?UTF-8?q?=E5=AE=9A=E4=B9=89audio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supervision/service/impl/ChatServiceImpl.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/supervision/service/impl/ChatServiceImpl.java b/src/main/java/com/supervision/service/impl/ChatServiceImpl.java index a9ebac6..1004093 100644 --- a/src/main/java/com/supervision/service/impl/ChatServiceImpl.java +++ b/src/main/java/com/supervision/service/impl/ChatServiceImpl.java @@ -114,7 +114,7 @@ public class ChatServiceImpl implements IChatService { .retrieve() .bodyToFlux(StreamResponse.class) .publishOn(Schedulers.boundedElastic()).mapNotNull(response -> { - log.info("response:时间:{},响应回答:{}", timeInterval.intervalMs(), JSONUtil.toJsonStr(response)); +// log.info("response:时间:{},响应回答:{}", timeInterval.intervalMs(), JSONUtil.toJsonStr(response)); Map map = new HashMap<>(); map.put("event", response.getEvent()); // 第一次接收数据时启动定时器 @@ -128,12 +128,10 @@ public class ChatServiceImpl implements IChatService { String text = predefinedAnswerAssistant.getHelloAnswer(); predefinedAnswerAssistant.resetInitTime(text); String voiceBaseId = MD5.create().digestHex(text); - map.put("audioId", voiceBaseId); - map.put("event", "message"); - log.info("首次接收dify响应,推送预定义打招呼回答id:【{}】,文本:{}", text, voiceBaseId); + log.info("首次接收dify响应,推送预定义打招呼回答id:【{}】,文本:{}", voiceBaseId, text); audioCache.put(voiceBaseId, predefinedAnswerAssistant.getHelloAnswerAudio(text)); sink.tryEmitNext(ServerSentEvent.>builder() - .data(map) + .data(Map.of("audioId", voiceBaseId, "event", "message")) .build()); Mono.delay(Duration.ofMillis(predefinedAnswerAssistant.getNextActivateTime())) .subscribe(t -> { @@ -141,19 +139,16 @@ public class ChatServiceImpl implements IChatService { if (!receivedAudio.get()) { String text2 = predefinedAnswerAssistant.getPredefinedAnswer(); String voiceBaseId2 = MD5.create().digestHex(text2); - map.put("audioId", voiceBaseId2); - map.put("event", "message"); - log.info("超过等待时间阈值,推送预定义回答id:【{}】,文本:{}", text2, voiceBaseId2); + log.info("超过等待时间阈值,推送预定义回答id:【{}】,文本:{}", voiceBaseId2, text2); audioCache.put(voiceBaseId2, predefinedAnswerAssistant.getPredefinedAnswerAudio(text2)); // 插入依次推送 sink.tryEmitNext(ServerSentEvent.>builder() - .data(map) + .data(Map.of("audioId", voiceBaseId2, "event", "message")) .build()); } }); } if (response.getEvent().equals("message") && response.getAnswer() != null) { - log.info("response:{}", response); //遍历answer中的每一个字符,判断是否为标点符号,如果是,说明是句子的结尾,将标点符号前的文本拼接到sentence中,并打印,然后清空sentence,如果标点符号后还有文本,将文本拼接到sentence中 for (char ch : response.getAnswer().toCharArray()) { sentence.append(ch);