Browse Source

移除语音生成模块

lighter 2 years ago
parent
commit
9e831e3e42

+ 0 - 5
pom.xml

@@ -156,11 +156,6 @@
             <version>24.0.1</version>
             <scope>compile</scope>
         </dependency>
-        <dependency>
-            <groupId>cn.xfyun</groupId>
-            <artifactId>websdk-java-speech</artifactId>
-            <version>2.0.1</version>
-        </dependency>
         <dependency>
             <groupId>org.bouncycastle</groupId>
             <artifactId>bcprov-jdk15on</artifactId>

+ 9 - 2
src/main/java/thyyxxk/webserver/controller/outpatient/voice/VoiceController.java

@@ -1,13 +1,14 @@
 package thyyxxk.webserver.controller.outpatient.voice;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import thyyxxk.webserver.config.auth.PassToken;
 import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.service.externalhttp.WebSocketService;
 import thyyxxk.webserver.utils.SnowFlakeId;
-import thyyxxk.webserver.utils.VoiceUtil;
 
 /**
  * @description: 生成语音文件接口
@@ -17,12 +18,18 @@ import thyyxxk.webserver.utils.VoiceUtil;
 @RestController
 @RequestMapping("/voice")
 public class VoiceController {
+    private final WebSocketService socketService;
+
+    @Autowired
+    public VoiceController(WebSocketService socketService) {
+        this.socketService = socketService;
+    }
 
     @PassToken
     @GetMapping("/textToSpeech")
     public ResultVo<String> textToSpeech(@RequestParam("text") String text) {
         String id = SnowFlakeId.instance().nextId();
-        return VoiceUtil.textToSpeech(text, id);
+        return socketService.textToSpeech(text, id);
     }
 
 }

+ 0 - 64
src/main/java/thyyxxk/webserver/scheduled/QueryNotifiedPatients.java

@@ -1,64 +0,0 @@
-package thyyxxk.webserver.scheduled;
-
-import com.alibaba.fastjson.JSON;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-import thyyxxk.webserver.dao.his.outpatient.triage.TriageDao;
-import thyyxxk.webserver.entity.outpatient.triage.MessageForPush;
-import thyyxxk.webserver.entity.outpatient.triage.MzfzPatientOrder;
-import thyyxxk.webserver.entity.outpatient.triage.TriageNotifyRelation;
-import thyyxxk.webserver.entity.socketmessage.ApiMessageBody;
-import thyyxxk.webserver.service.externalhttp.WebSocketService;
-import thyyxxk.webserver.utils.VoiceUtil;
-
-import java.util.List;
-
-@Slf4j
-@Component
-public class QueryNotifiedPatients {
-    private final TriageDao dao;
-    @Value("${execute-scheduled}")
-    private Boolean executeScheduled;
-    private final WebSocketService socketService;
-
-    @Autowired
-    public QueryNotifiedPatients(TriageDao dao, WebSocketService socketService) {
-        this.dao = dao;
-        this.socketService = socketService;
-    }
-
-    @Scheduled(fixedRate = 6000)
-    public void query() {
-        if (executeScheduled) {
-            List<TriageNotifyRelation> unNotifiedList = dao.selectUnNotifiedList();
-            if (null == unNotifiedList || unNotifiedList.isEmpty()) {
-                return;
-            }
-            for (TriageNotifyRelation item : unNotifiedList) {
-                MzfzPatientOrder patient = dao.getPatientTriageInfo(item.getSerialNo());
-                MessageForPush param = new MessageForPush();
-                param.setAction(1);
-                param.setSerialNo(patient.getSerialNo());
-                param.setFzNo(patient.getFzNo());
-                param.setName(patient.getName());
-                param.setDeptName(patient.getDeptName());
-                param.setRoomNo(patient.getRoomNo());
-                param.setRoomCode(patient.getRoomCode());
-                final String msg = JSON.toJSONString(param);
-                String text = String.format("请%s号%s,到%s%s号诊室就诊。", param.getFzNo(), param.getName(),
-                        param.getDeptName(), param.getRoomNo());
-                VoiceUtil.textToSpeech(text, String.valueOf(param.getSerialNo()));
-
-                ApiMessageBody messageBody = new ApiMessageBody(msg);
-                messageBody.setSid(item.getSocketSid());
-                messageBody.setRoomCode(item.getRoomCode());
-                socketService.sendFloorTriageMessage(messageBody);
-                socketService.sendRoomTriageMessage(messageBody);
-                dao.updateNotifyDatetime(param.getSerialNo());
-            }
-        }
-    }
-}

+ 3 - 0
src/main/java/thyyxxk/webserver/service/externalhttp/WebSocketService.java

@@ -37,4 +37,7 @@ public interface WebSocketService {
 
     @Get("/isBeingEditing?documentId={documentId}")
     ResultVo<String> isBeingEditing(@Var("documentId") String documentId);
+
+    @Get("/textToSpeech?text={text}&id={id}")
+    ResultVo<String> textToSpeech(@Var("text") String text, @Var("id") String id);
 }

+ 1 - 2
src/main/java/thyyxxk/webserver/service/outpatient/triage/RoomScreenService.java

@@ -15,7 +15,6 @@ import thyyxxk.webserver.entity.socketmessage.ApiMessageBody;
 import thyyxxk.webserver.service.externalhttp.WebSocketService;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
-import thyyxxk.webserver.utils.VoiceUtil;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -57,7 +56,7 @@ public class RoomScreenService {
         if (param.getAction() == 1) {
             String text = String.format("请%s号%s,到%s%s号诊室就诊。", param.getFzNo(), param.getName(),
                     param.getDeptName(), param.getRoomNo());
-            VoiceUtil.textToSpeech(text, String.valueOf(param.getSerialNo()));
+            socketService.textToSpeech(text, String.valueOf(param.getSerialNo()));
         }
         ApiMessageBody messageBody = new ApiMessageBody(JSON.toJSONString(param));
         messageBody.setSid(param.getRoomCode() + "-triageRoomScreen");

+ 1 - 2
src/main/java/thyyxxk/webserver/service/outpatient/triage/TriageService.java

@@ -19,7 +19,6 @@ import thyyxxk.webserver.service.externalhttp.WebSocketService;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 import thyyxxk.webserver.utils.TokenUtil;
-import thyyxxk.webserver.utils.VoiceUtil;
 
 import java.util.*;
 
@@ -227,7 +226,7 @@ public class TriageService {
         String text = String.format("请%s号%s,到%s%s号诊室就诊。", messageForPush.getFzNo(), messageForPush.getName(),
                 messageForPush.getDeptName(), messageForPush.getRoomNo());
         log.info("消息推送>>> {}\n{}", messageForPush, text);
-        VoiceUtil.textToSpeech(text, String.valueOf(param.getSerialNo()));
+        socketService.textToSpeech(text, String.valueOf(param.getSerialNo()));
         final String msg = JSON.toJSONString(messageForPush);
         TriageNotifyRelation notifyRelation = dao.selectTriageNotifyRelation(messageForPush.getSerialNo());
         if (null == notifyRelation) {

+ 0 - 95
src/main/java/thyyxxk/webserver/utils/VoiceUtil.java

@@ -1,95 +0,0 @@
-package thyyxxk.webserver.utils;
-
-import cn.xfyun.api.TtsClient;
-import cn.xfyun.model.response.TtsResponse;
-import cn.xfyun.service.tts.AbstractTtsWebSocketListener;
-import lombok.extern.slf4j.Slf4j;
-import okhttp3.Response;
-import okhttp3.WebSocket;
-import thyyxxk.webserver.config.exception.ExceptionEnum;
-import thyyxxk.webserver.entity.ResultVo;
-
-import java.io.File;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author dj
- */
-@Slf4j
-public class VoiceUtil {
-    private static final String appId = "fdde4cef";
-    private static final String apiKey = "95a78dd3cfcc4863e3c003352ca8ec65";
-    private static final String apiSecret = "OWZjZGE4NjI3MDdkYzg4ZjllY2VjNGQ0";
-
-    private static void deleteOldFile(String serialNo) {
-        String path = "D:\\apache-tomcat-9.0.30\\webapps\\voices\\" + serialNo + ".mp3";
-        File file = new File(path);
-        if (file.exists()) {
-            if (file.delete()) {
-                log.info("删除重复文件:{}", serialNo);
-            }
-        }
-    }
-
-    public static ResultVo<String> textToSpeech(String data, String id) {
-        deleteOldFile(id);
-        String voiceUrl = "http://172.16.32.160:8888/voices/" + id + ".mp3";
-        String filePath = "D:\\apache-tomcat-9.0.30\\webapps\\voices\\" + id + ".mp3";
-        final Boolean[] progress = { false, null };
-        final String[] message = {""};
-        try  {
-            TtsClient ttsClient = new TtsClient.Builder()
-                    .signature(appId, apiKey, apiSecret)
-                    .vcn("aisjinger")
-                    .volume(100)
-                    .build();
-            File file = new File(filePath);
-            ttsClient.send(data, new AbstractTtsWebSocketListener(file) {
-                @Override
-                public void onSuccess(byte[] bytes) {
-                    progress[0] = true;
-                }
-                @Override
-                public void onFail(WebSocket webSocket, Throwable throwable, Response response) {
-                    log.error("生成语音文件失败:{}", throwable.getMessage());
-                    message[0] = throwable.getMessage();
-                }
-
-                @Override
-                public void onBusinessFail(WebSocket webSocket, TtsResponse ttsResponse) {
-                    log.error("生成语音文件失败:{}", ttsResponse.toString());
-                    message[0] = ttsResponse.toString();
-                }
-
-                @Override
-                public void onClosing(WebSocket webSocket, int code, String reason) {
-                    super.onClosing(webSocket, code, reason);
-                }
-
-                @Override
-                public void onClosed(WebSocket webSocket, int code, String reason) {
-                    super.onClosed(webSocket, code, reason);
-                    progress[1] = true;
-                }
-            });
-        }catch (Exception e){
-            log.error("生成语音文件失败", e);
-            log.error("错误码查询链接:https://www.xfyun.cn/document/error-code");
-            message[0] = e.getMessage();
-            progress[1] = true;
-        }
-
-        while (null == progress[1]) {
-            try {
-                TimeUnit.MILLISECONDS.sleep(1000);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-        }
-
-        if (progress[0]) {
-            return ResultVoUtil.success(voiceUrl);
-        }
-        return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, message[0]);
-    }
-}