ソースを参照

语音相关代码优化提交

yjwang 2 週間 前
コミット
130a380623

+ 2 - 1
fs-common-api/src/main/resources/application.yml

@@ -5,4 +5,5 @@ server:
 spring:
   profiles:
 #    active: dev
-    active: druid-ylrz
+#    active: druid-ylrz
+    active: druid-hzjs-test

+ 2 - 1
fs-company-app/src/main/resources/application.yml

@@ -6,4 +6,5 @@ server:
 spring:
   profiles:
 #    active: druid-fcky-test
-    active: druid-bjczwh-test
+#    active: druid-bjczwh-test
+    active: druid-hzjs-test

+ 2 - 1
fs-qw-voice/src/main/resources/application.yml

@@ -6,4 +6,5 @@ server:
 # Spring配置
 spring:
   profiles:
-    active: druid-jnmy-test
+#    active: druid-jnmy-test
+    active: druid-hzjs-test

+ 55 - 2
fs-service/src/main/java/com/fs/fastgptApi/util/AudioUtils.java

@@ -45,9 +45,62 @@ public class AudioUtils {
 
     /**
      * 工具地址
+     * 优先级:环境变量 FFMPEG_PATH > 系统 PATH 查找 > 默认 c:\\ffmpeg\\bin\\
      **/
-    static String path = "c:\\";
-    static String destinationDir = "c:\\hook\\";
+    static String path = initFfmpegPath();
+    static String destinationDir = initDestinationDir();
+
+    private static String initFfmpegPath() {
+        // 1. 优先读环境变量 FFMPEG_PATH
+        String envPath = System.getenv("FFMPEG_PATH");
+        if (envPath != null && !envPath.trim().isEmpty()) {
+            String normalized = envPath.endsWith("\\") || envPath.endsWith("/") ? envPath : envPath + File.separator;
+            log.info("[AudioUtils] 使用环境变量 FFMPEG_PATH: {}", normalized);
+            return normalized;
+        }
+        // 2. 从系统 PATH 中查找 ffmpeg.exe 真实位置
+        String ffmpegPath = resolveFfmpegFromPath();
+        if (ffmpegPath != null) {
+            String dir = ffmpegPath.substring(0, ffmpegPath.lastIndexOf(File.separator) + 1);
+            log.info("[AudioUtils] 从 PATH 查找到 ffmpeg,目录: {}", dir);
+            return dir;
+        }
+        // 3. 兜底默认值
+        log.info("[AudioUtils] 未找到 ffmpeg,使用默认路径: c:\\ffmpeg\\bin\\");
+        return "c:\\ffmpeg\\bin\\";
+    }
+
+    /**
+     * 遍历 PATH 环境变量,查找 ffmpeg.exe 的真实绝对路径
+     */
+    private static String resolveFfmpegFromPath() {
+        String pathEnv = System.getenv("PATH");
+        if (pathEnv == null || pathEnv.isEmpty()) {
+            return null;
+        }
+        String[] dirs = pathEnv.split(File.pathSeparator);
+        for (String dir : dirs) {
+            if (dir == null || dir.trim().isEmpty()) {
+                continue;
+            }
+            File ffmpegFile = new File(dir, "ffmpeg.exe");
+            if (ffmpegFile.exists() && ffmpegFile.isFile()) {
+                return ffmpegFile.getAbsolutePath();
+            }
+        }
+        return null;
+    }
+
+    private static String initDestinationDir() {
+        String envDir = System.getenv("FFMPEG_TEMP_DIR");
+        if (envDir != null && !envDir.trim().isEmpty()) {
+            String normalized = envDir.endsWith("\\") || envDir.endsWith("/") ? envDir : envDir + File.separator;
+            log.info("[AudioUtils] 使用环境变量 FFMPEG_TEMP_DIR: {}", normalized);
+            return normalized;
+        }
+        log.info("[AudioUtils] 未配置 FFMPEG_TEMP_DIR,使用默认值: c:\\hook\\");
+        return "c:\\hook\\";
+    }
     public static AudioVO createVoiceUrl(Long id,String userVoiceUrl){
         String fileUrl = staticAiHostProper.getVoiceApi() + "/app/common/createVoiceUrl?id=" + id + "&userVoiceUrl=" + userVoiceUrl;
 

+ 1 - 1
fs-service/src/main/resources/application-config-druid-hzjs.yml

@@ -97,7 +97,7 @@ headerImg:
 ipad:
   ipadUrl: http://ipad.jsjkhangzhou.com
   aiApi:
-  voiceApi:
+  voiceApi: http://127.0.0.1:8009
   commonApi:
 wx_miniapp_temp:
   pay_order_temp_id:

+ 2 - 2
fs-user-app/src/main/resources/application.yml

@@ -13,5 +13,5 @@ spring:
 #    active: druid-sxjz
 #    active: druid-qdtst
 #    active: druid-yzt
-    active: druid-bjczwh-test
-#    active: druid-hzjs-test
+#    active: druid-bjczwh-test
+    active: druid-hzjs-test