|
|
@ -76,25 +76,27 @@ public class ChatServiceImpl implements IChatService {
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
map.put("event", response.getEvent());
|
|
|
|
map.put("event", response.getEvent());
|
|
|
|
if (response.getEvent().equals("message") && response.getAnswer() != null) {
|
|
|
|
if (response.getEvent().equals("message") && response.getAnswer() != null) {
|
|
|
|
String voiceBaseId = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
//遍历answer中的每一个字符,判断是否为标点符号,如果是,说明是句子的结尾,将标点符号前的文本拼接到sentence中,并打印,然后清空sentence,如果标点符号后还有文本,将文本拼接到sentence中
|
|
|
|
//遍历answer中的每一个字符,判断是否为标点符号,如果是,说明是句子的结尾,将标点符号前的文本拼接到sentence中,并打印,然后清空sentence,如果标点符号后还有文本,将文本拼接到sentence中
|
|
|
|
for (char ch : response.getAnswer().toCharArray()) {
|
|
|
|
for (char ch : response.getAnswer().toCharArray()) {
|
|
|
|
sentence.append(ch);
|
|
|
|
sentence.append(ch);
|
|
|
|
if (ch == '。' || ch == '!' || ch == '?' || ch == ',' || ch == '、' || ch == '‘' || ch == '’' || ch == '“' || ch == '”') { // Check for punctuation marks
|
|
|
|
if (ch == '。' || ch == '!' || ch == '?' || ch == ',' || ch == '、' || ch == '‘' || ch == '’' || ch == '“' || ch == '”') { // Check for punctuation marks
|
|
|
|
log.info(sentence.toString());
|
|
|
|
log.info(sentence.toString());
|
|
|
|
TtsResultDTO ttsResultDTO = TtsUtil.ttsTransform(sentence.toString());
|
|
|
|
TtsResultDTO ttsResultDTO = TtsUtil.ttsTransform(sentence.toString());
|
|
|
|
|
|
|
|
String voiceBaseId = UUID.randomUUID().toString();
|
|
|
|
voiceCache.put(voiceBaseId, ttsResultDTO.getAudio());
|
|
|
|
voiceCache.put(voiceBaseId, ttsResultDTO.getAudio());
|
|
|
|
map.put("audioId", voiceBaseId);
|
|
|
|
map.put("audioId", voiceBaseId);
|
|
|
|
sentence.setLength(0); // Clear the sentence
|
|
|
|
sentence.setLength(0); // Clear the sentence
|
|
|
|
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (response.getEvent().equals("message_end") && !sentence.isEmpty()) {
|
|
|
|
if (response.getEvent().equals("message_end") && !sentence.isEmpty()) {
|
|
|
|
log.info(sentence.toString());
|
|
|
|
log.info(sentence.toString());
|
|
|
|
TtsResultDTO ttsResultDTO = TtsUtil.ttsTransform(sentence.toString());
|
|
|
|
TtsResultDTO ttsResultDTO = TtsUtil.ttsTransform(sentence.toString());
|
|
|
|
|
|
|
|
String voiceBaseId = UUID.randomUUID().toString();
|
|
|
|
voiceCache.put(voiceBaseId, ttsResultDTO.getAudio());
|
|
|
|
voiceCache.put(voiceBaseId, ttsResultDTO.getAudio());
|
|
|
|
map.put("audioId", voiceBaseId);
|
|
|
|
map.put("audioId", voiceBaseId);
|
|
|
|
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
});
|
|
|
|
});
|
|
|
|