场景近期在做微信开发时,需要获取用户发给公众服务号的语音留言。而从微信服务端下载来的语音格式却是amr的格式,同样的你手机录音、Android语音等也都是生成amr格式文件。但当你想在web页面去播放此文件时,就困难...
场景
近期在做微信开发时,需要获取用户发给公众服务号的语音留言。而从微信服务端下载来的语音格式却是amr的格式,同样的你手机录音、Android语音等也都是生成amr格式文件。但当你想在web页面去播放此文件时,就困难了。因为无论是当前HTML5的<audio>标签,还是众多的播放插件都不支持amr格式文件的播放。所以,你不得不先把它转码为常见的MP3等类型文件。
maven
<!-- https://mvnrepository.com/artifact/ws.schild/jave-core --> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-core</artifactId> <version>2.4.4</version> </dependency>
从我的Mac book 开发环境开始玩。
public class AmrToMp3 { public static void main(String[] args) throws Exception { changeTemp(); } public static void changeTemp() throws InputFormatException { File source = new File("/Users/daji/Downloads/1.amr"); //源文件 File target = new File("/Users/daji/Downloads/1.mp3"); //目标文件 AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp3"); attrs.setAudioAttributes(audio); Encoder encoder = new Encoder(); try { MultimediaObject multimediaObject = new MultimediaObject(source); encoder.encode(multimediaObject,target, attrs); } catch (IllegalArgumentException | EncoderException e) { e.printStackTrace(); } } }
跑一下. GG
十二月 05, 2018 6:42:11 下午 ws.schild.jave.DefaultFFMPEGLocator copyFile 严重: Could not find ffmpeg executable for native/ffmpeg-x86_64-osx is the correct platform jar included? Exception in thread "main" java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.nio.file.Files.copy(Files.java:2984) at ws.schild.jave.DefaultFFMPEGLocator.copy(DefaultFFMPEGLocator.java:144) at ws.schild.jave.DefaultFFMPEGLocator.copyFile(DefaultFFMPEGLocator.java:123) at ws.schild.jave.DefaultFFMPEGLocator.<init>(DefaultFFMPEGLocator.java:84) at ws.schild.jave.Encoder.<init>(Encoder.java:80) at cn.hitstone.media.util.AmrToMp3.changeTemp(AmrToMp3.java:20) at cn.hitstone.media.util.AmrToMp3.main(AmrToMp3.java:10) Process finished with exit code 1
意思就是要安装一个ffmpeg-x86_64-osx
<!-- https://mvnrepository.com/artifact/ws.schild/jave-native-osx64 --> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-osx64</artifactId> <version>2.4.4</version> </dependency>
搞定 so easy
Windows 版导这个
<!-- https://mvnrepository.com/artifact/ws.schild/jave-native-win64 --><dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-win64</artifactId> <version>2.4.4</version></dependency>
Linux 版导这个
<!-- https://mvnrepository.com/artifact/ws.schild/jave-native-linux64 --><dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-linux64</artifactId> <version>2.4.4</version></dependency>
测试结果
沃梦达教程
本文标题为:JAVA 音频转换AMR 转MP3,OS,Linux cent os 7
猜你喜欢
- ExecutorService Callable Future多线程返回结果原理解析 2023-06-01
- Java中的日期时间处理及格式化处理 2023-04-18
- JSP 制作验证码的实例详解 2023-07-30
- Java实现顺序表的操作详解 2023-05-19
- 基于Java Agent的premain方式实现方法耗时监控问题 2023-06-17
- JSP页面间传值问题实例简析 2023-08-03
- Spring Security权限想要细化到按钮实现示例 2023-03-07
- SpringBoot使用thymeleaf实现一个前端表格方法详解 2023-06-06
- Springboot整合minio实现文件服务的教程详解 2022-12-03
- 深入了解Spring的事务传播机制 2023-06-02