|
@@ -9,6 +9,8 @@ import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.Response;
|
|
|
import okhttp3.WebSocket;
|
|
|
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.thyy.thirdpartapi.tts.Tts;
|
|
|
import org.thyy.thirdpartapi.tts.TtsConfig;
|
|
@@ -24,6 +26,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service(value = "xf")
|
|
|
+@Configuration
|
|
|
+@ConditionalOnProperty(prefix = "tts", name = "service", matchIfMissing = true, havingValue = "xf")
|
|
|
public class XfTtsApi implements Tts {
|
|
|
private TtsClient ttsClient;
|
|
|
private TtsConfig cfg;
|
|
@@ -50,39 +54,41 @@ public class XfTtsApi implements Tts {
|
|
|
|
|
|
CompletableFuture<Void> future = new CompletableFuture<>();
|
|
|
|
|
|
- try {
|
|
|
- File file = new File(filePath);
|
|
|
- ttsClient.send(request.getText(), new AbstractTtsWebSocketListener(file) {
|
|
|
- @Override
|
|
|
- public void onSuccess(byte[] bytes) {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFail(WebSocket webSocket, Throwable throwable, Response response) {
|
|
|
- log.error("[onFail]生成语音文件失败:{}", throwable.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onBusinessFail(WebSocket webSocket, TtsResponse ttsResponse) {
|
|
|
- log.error("[onBusinessFail]生成语音文件失败:{}", 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);
|
|
|
- future.complete(null);
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("生成语音文件失败", e);
|
|
|
- log.error("错误码查询链接:https://www.xfyun.cn/document/error-code");
|
|
|
- future.completeExceptionally(e);
|
|
|
- }
|
|
|
+// try {
|
|
|
+// File file = new File(filePath);
|
|
|
+// ttsClient.send(request.getText(), new AbstractTtsWebSocketListener(file) {
|
|
|
+// @Override
|
|
|
+// public void onSuccess(byte[] bytes) {
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onFail(WebSocket webSocket, Throwable throwable, Response response) {
|
|
|
+// log.error("[onFail]生成语音文件失败:{}", throwable.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onBusinessFail(WebSocket webSocket, TtsResponse ttsResponse) {
|
|
|
+// log.error("[onBusinessFail]生成语音文件失败:{}", 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);
|
|
|
+// future.complete(null);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("生成语音文件失败", e);
|
|
|
+// log.error("错误码查询链接:https://www.xfyun.cn/document/error-code");
|
|
|
+// future.completeExceptionally(e);
|
|
|
+// }
|
|
|
+
|
|
|
+ future.complete(null);
|
|
|
|
|
|
String voiceUrl = cfg.getSpeechUrl() + "/" + request.getId() + ".mp3";
|
|
|
AtomicReference<ResultVo<String>> resultVo = new AtomicReference<>(R.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, ""));
|