Bladeren bron

使用枚举这样有代码提示

xiaochan 4 maanden geleden
bovenliggende
commit
352494db75

+ 8 - 16
thyy-thirdpart-api/HELP.md

@@ -1,27 +1,19 @@
 # 关于tts语言生成的配置注意
 
-1. 需要实现 这个接口
+1. 需要实现 这个接口 
     ```java
+    import org.springframework.stereotype.Service;
+   
     @Slf4j
-    // 服务的名字就是配置文件中的名字
-    @Service(value = "xf")
+    @Service
+    @ConditionalOnProperty(prefix = "thyy.tts", name = "service", havingValue = "xfyun")
     public class XfTtsApi implements Tts {
         
     }
     ```
 2. 配置文件中
    ```yaml
-   thyy:
-     tts:
-       directory: D:\a.snapshot\resource\voice #文件存放的路径
-       speech-url: http://172.16.32.160:8080/resource/voice # 生成的地址
-       config:
-         xf:  # 这个key就是上面服务的名字不要写错
-           app-id: fdde4cef
-           api-key: 95a78dd3cfcc4863e3c003352ca8ec65
-           api-secret: OWZjZGE4NjI3MDdkYzg4ZjllY2VjNGQ0
-         xxx:
-           app-id: xxxx
-           api-key: xxxxx
-           api-secret: xxxxx
+    thyy:
+      tts:  
+        service: xfyun
    ```

+ 14 - 1
thyy-thirdpart-api/src/main/java/org/thyy/thirdpartapi/tts/TtsConfig.java

@@ -1,6 +1,8 @@
 package org.thyy.thirdpartapi.tts;
 
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.Getter;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 
@@ -9,9 +11,20 @@ import org.springframework.stereotype.Component;
 @Data
 @ConfigurationProperties("thyy.tts")
 public class TtsConfig {
+
+    @AllArgsConstructor
+    @Getter
+    public static enum ServiceName {
+        xfyun("xfyun"),
+        ttstext("ttstext");
+        private final String name;
+    }
+
     private String directory;
     private String speechUrl;
-    private String service;
+    private ServiceName service;
+
+
     private String appId;
     private String apiKey;
     private String apiSecret;