当前位置: 首页 > 工具软件 > JLayer > 使用案例 >

jlayer播放音乐和读

齐宗清
2023-12-01

播放

    <dependency>
            <groupId>javazoom</groupId>
            <artifactId>jlayer</artifactId>
            <version>1.0.1</version>
        </dependency>

package com.zhk.swagger.controller;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.advanced.AdvancedPlayer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@RestController
public class TestController {

    @RequestMapping("/test")
    public String test()  {
        new Thread(()-> {
            try {
                // 使用JavaZoom库读取MP3文件
                FileInputStream fis = new FileInputStream(new File("E:\\lqbz\\Shadow of the Sun-Max Elto.128.mp3"));
                AdvancedPlayer player = new AdvancedPlayer(fis);
                // 播放MP3文件
                player.play();
            } catch (JavaLayerException | IOException e) {
                e.printStackTrace();
            }
        }).start();

        return "success";
    }
}


读::需要再jdk配置东西 https://download.csdn.net/download/weixin_49390750/87677484?spm=1001.2014.3001.5501 解压扔到bin目录下

    <dependency>
            <groupId>com.hynnet</groupId>
            <artifactId>jacob</artifactId>
            <version>1.18</version>
        </dependency>

 @RequestMapping("/test")
    @SneakyThrows
    public String test()  {
        ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
        try {
            sap.setProperty("Volume",new Variant(100));              // 音量 0-100
            sap.setProperty("Rate",new Variant(-3));                 // 语音朗读速度 -10 到 +10
            Dispatch sapo = sap.getObject();
            // 获取执行对象
            Dispatch.call(sapo,"Speak",new Variant("测试测试测试"));    	// 执行朗读
            sapo.safeRelease();                                     // 关闭执行对象
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            sap.safeRelease();                                      // 关闭执行对象
        }

        return "success";
    }

http://www.shuoyiduan.com/ 可转换mp4

systemctl enable xxx命令 重启就执行的linux的命令

 类似资料: