|
|
|
package com.supervision.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.parser.Feature;
|
|
|
|
import com.supervision.dto.paddlespeech.res.TtsResultDTO;
|
|
|
|
import com.supervision.model.dify.DIFYChatReqInputVO;
|
|
|
|
import com.supervision.model.dify.DifyChatReqVO;
|
|
|
|
import com.supervision.model.dify.DifyChatResVO;
|
|
|
|
import com.supervision.service.IChatService;
|
|
|
|
import com.supervision.util.AsrUtil;
|
|
|
|
import com.supervision.util.DifyApiUtil;
|
|
|
|
import com.supervision.util.TtsUtil;
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
public class ChatServiceImpl implements IChatService {
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private DifyApiUtil difyApiUtil;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String talk(MultipartFile file) {
|
|
|
|
String talkResult = "";
|
|
|
|
try {
|
|
|
|
DifyChatReqVO difyChatReqVO = new DifyChatReqVO();
|
|
|
|
difyChatReqVO.setUser("admin");
|
|
|
|
DIFYChatReqInputVO inputs = new DIFYChatReqInputVO();
|
|
|
|
inputs.setQuery(AsrUtil.asrTransformByBytes(file.getBytes()));
|
|
|
|
difyChatReqVO.setInputs(inputs);
|
|
|
|
String response = difyApiUtil.chat(difyChatReqVO);
|
|
|
|
log.info("response:{}", response);
|
|
|
|
TtsResultDTO ttsResultDTO = TtsUtil.ttsTransform(response);
|
|
|
|
talkResult = JSON.toJSONString(ttsResultDTO);
|
|
|
|
log.info("ttsResultDTO:{}", JSON.toJSONString(ttsResultDTO));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
return talkResult;
|
|
|
|
}
|
|
|
|
}
|