jek 4 kuukautta sitten
vanhempi
commit
2cac5fa9be

+ 18 - 14
src/main/java/com/zhili/stationcontrol/tts/controller/TtsController.java

@@ -91,20 +91,24 @@ public class TtsController {
 
     @GetMapping("/music")
     public String music() throws UnsupportedAudioFileException, IOException, LineUnavailableException, InterruptedException {
-        File file = new File("/static/wav/hdzqdd.wav");
-        // 创建一个AudioInputStream
-        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
-        // 使用Clip类来处理音频流
-        Clip clip = AudioSystem.getClip();
-        // 打开声卡并加载音频数据
-        clip.open(audioInputStream);
-        // 开始播放
-        clip.start();
-        Thread.sleep(clip.getMicrosecondLength() / 1000);
-        // 等待音频播放完成
-        clip.drain();
-        // 关闭声卡
-        clip.close();
+//        File file = new File("/static/wav/hdzqdd.wav");
+//        // 创建一个AudioInputStream
+//        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
+//        // 使用Clip类来处理音频流
+//        Clip clip = AudioSystem.getClip();
+//        // 打开声卡并加载音频数据
+//        clip.open(audioInputStream);
+//        // 开始播放
+//        clip.start();
+//        Thread.sleep(clip.getMicrosecondLength() / 1000);
+//        // 等待音频播放完成
+//        clip.drain();
+//        // 关闭声卡
+//        clip.close();
+        String path = "/static/wav/hdzqdd.wav";
+        //log.info("path:{}", path);
+        Process exec = Runtime.getRuntime().exec("play " + path);
+        exec.waitFor();
         return "ok";
     }
 }