Springboot AMR格式音频转换MP3
文章目录
- html5中audio支持音频格式
- Java AMR格式音频转MP3
html5中audio支持音频格式
HTML5 Audio标签能够支持wav, mp3, ogg, acc, webm等格式
但有个很重要的音乐文件格式amr(扩展名amr)却在各大浏览器中都没有内置的支持。
音频格式 | Chrome | Firefox | IE9 | Opera | Safari |
---|---|---|---|---|---|
OGG | 支持 | 支持 | 支持 | 不支持 | 不支持 |
MP3 | 支持 | 不支持 | 支持 | 不支持 | 支持 |
WAV | 不支持 | 支持 | 不支持 | 支持 | 不支持 |
Java AMR格式音频转MP3
pom
ws.schild(Windows版本、Linux版本)
<!-- 文件格式转换依赖--><!-- https://mvnrepository.com/artifact/ws.schild/jave-core --><dependency><groupId>ws.schild</groupId><artifactId>jave-core</artifactId><version>2.4.4</version></dependency><!-- https://mvnrepository.com/artifact/org.springframework/spring-mock --><dependency><groupId>org.springframework</groupId><artifactId>spring-mock</artifactId><version>2.0.8</version></dependency><!-- https://mvnrepository.com/artifact/ws.schild/jave-native-win64 Windows版本--><dependency><groupId>ws.schild</groupId><artifactId>jave-native-win64</artifactId><version>2.4.4</version></dependency><!-- https://mvnrepository.com/artifact/ws.schild/jave-native-linux64 Linux版本--><dependency><groupId>ws.schild</groupId><artifactId>jave-native-linux64</artifactId><version>2.4.4</version></dependency>
properties
filePath:sourcePath: /tmp/matter/tempFilePath/sourcePath/uploadPath: /tmp/matter/tempFilePath/uploadPath/
class工具类
package com.tqservice.web.core.utils;import org.springframework.beans.factory.annotation.Value; import org.springframework.mock.web.MockMultipartFile; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import ws.schild.jave.AudioAttributes; import ws.schild.jave.Encoder; import ws.schild.jave.EncodingAttributes; import ws.schild.jave.MultimediaObject;import java.io.*;/*** 文件格式转换工具*/ @Component public class FileFormat {@Value("${filePath.sourcePath}")private String AMRLOCALPATH;@Value("${filePath.uploadPath}")private String MP3LOCALPATH;/*** 上传文件下载到本地** @param multipartFile*/public String downloadFile(MultipartFile multipartFile) {OutputStream os = null;InputStream inputStream = null;String fileName = null;String fullPath = null;try {inputStream = multipartFile.getInputStream();fileName = multipartFile.getOriginalFilename();} catch (IOException e) {e.printStackTrace();}try {// 保存到临时文件byte[] bs = new byte[1024];// 读取到的数据长度int len;// 输出的文件流保存到本地文件,判断文件夹是否存在File tempFile = new File(AMRLOCALPATH);if (!tempFile.exists()) {tempFile.mkdirs();}os = new FileOutputStream(tempFile.getPath() + File.separator + fileName);// 开始读取while ((len = inputStream.read(bs)) != -1) {os.write(bs, 0, len);}fullPath = AMRLOCALPATH + multipartFile.getOriginalFilename();} catch (IOException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} finally {// 完毕,关闭所有链接try {os.close();inputStream.close();return fullPath;} catch (IOException e) {e.printStackTrace();return fullPath;}}}/*** 文件格式转换** @param multipartFile 目标文件* @return*/public MultipartFile formatConversion(MultipartFile multipartFile) {MockMultipartFile mockMultipartFile = null;try {//转码源文件String sourcePath = downloadFile(multipartFile);if (null == sourcePath) {return mockMultipartFile;}File source = new File(sourcePath);//判断文件夹是否存在File file = new File(MP3LOCALPATH);if (!file.exists()) {file.mkdirs();}//转码本地输出文件String saveFilePath = multipartFile.getOriginalFilename();saveFilePath = MP3LOCALPATH + saveFilePath.substring(0, saveFilePath.lastIndexOf(".") + 1) + "mp3";File target = new File(saveFilePath);//Audio AttributesAudioAttributes audio = new AudioAttributes();audio.setCodec("libmp3lame");audio.setBitRate(128000);audio.setChannels(2);audio.setSamplingRate(44100);//Encoding attributesEncodingAttributes attrs = new EncodingAttributes();attrs.setFormat("mp3");attrs.setAudioAttributes(audio);//EncodeEncoder encoder = new Encoder();encoder.encode(new MultimediaObject(source), target, attrs);//转MultipartFileFileInputStream fileInputStream = new FileInputStream(target);mockMultipartFile = new MockMultipartFile(target.getName(), fileInputStream);} catch (Exception ex) {ex.printStackTrace();}return mockMultipartFile;}/*** 删除临时文件** @param fileName*/public void deleteTempFile(String fileName) {String amrFilePath = AMRLOCALPATH + fileName.substring(0, fileName.lastIndexOf(".") + 1) + "amr";String mp3FilePath = MP3LOCALPATH + fileName;File amrFile = new File(amrFilePath);File mp3File = new File(mp3FilePath);if (amrFile.isFile() && amrFile.exists()) {//存在则进行删除amrFile.delete();}if (mp3File.isFile() && mp3File.exists()) {mp3File.delete();}} }
Springboot AMR格式音频转换MP3相关推荐
- java后台 amr格式音频转为mp3格式
最近项目用到读取amr格式的音频,但是h5不支持这种格式,前台处理不太擅长感觉太过麻烦,所以还是在后端转格式吧. 用到一个jar: jave.jar 网址:https://www.sauronsoft ...
- amr格式音频转为mp3格式
最近项目用到读取amr格式的音频,但是h5不支持这种格式,网上有一些是通过插件的方式来读取,amrlib.js之类,但是不擅长前端,而且有一些插件是要求把文件转为base64编码格式,然后把这些bas ...
- jave.jar amr格式音频转为mp3格式 部署linux会有一个问题 转换出来的MP3文件是0k
jave就是封装了一层对外部ffmpeg的调用. 而windows上能转换是因为:ffmpeg.exe 这个程序没问题. 而Linux上转换失败也是因为 ffmpeg 这个可能版本太老或依赖库缺失. ...
- 音频amr格式怎么转换成mp3?
昨天利用十分钟的功夫做了一个音频amr格式转换成mp3的方法讲解,这个方法一共用了四个步骤来实现将音频amr转换成MP3的操作.amr是手机录音的一种保存格式,特点是体积小,传输速度快,资源消耗量低, ...
- 音频amr格式怎么转换成mp3
大家知道吗?在我们日常工作和生活中接触到的每一种文件都有对应的一种格式,这些不同的格式应用在特定的场景下起发挥最大的优势,为大家提供了很大的方便.很多小伙伴可能还很茫然,我们举个例子说明一下大家就知道 ...
- 电脑音频转换mp3格式怎么弄,教你音频怎么转换mp3格式
mp3格式是目前几乎全兼容的格式了,在我们参加一些会议或讲座时,需要录制一些重要的信息,结束后再进行复盘或分享.然而,不同的录制工具录制的音频格式也不同,这时使用软件将音频统一成mp3格式的话,就会方 ...
- html格式怎么转换mp3,mp3支持什么音频格式_mp3音频格式怎么转换-太平洋IT百科手机版...
现在手机的功能越来越多,逐渐取代了mp3.对于很多80后.90后人来说,整个青春期的记忆都和MP3有关.那个时候人手拿一部mp3,也是炫耀的资本.现在很少有人再用mp3了,更别说mp3支持什么音频格式 ...
- 如何将M4A格式音频转换成MP3格式?分享两个方法给大家!
M4A是一种数字音频压缩格式,通常用于存储iTunes Store上的音乐和其他数字音频文件.但是,有时候您可能需要将M4A文件转换为MP3格式以便在其他设备上播放或共享.下面我们将介绍如何将M4A格 ...
- 如何将m4a音频转换mp3格式,5种简单方法帮你处理
如何将m4a音频转换mp3格式?这个问题想必在工作生活中经常遇到吧.为什么要将m4a音频转换mp3格式呢?首先,M4A是一种较新的高质量音频文件格式,通常用于存储高保真度的音频文件,例如音乐录音室的原 ...
- m4a音频转换mp3格式的方法
很多朋友都在问m4a音频转换mp3格式的方法这个问题,小编根据大家的实际要求和诉求在网上寻找了很多的m4a转换成mp3的方法,这些方法都可以将m4a转换成mp3,但是在速度和稳定性方面有所差异.尤其是 ...
最新文章
- 网校mysql设计规范_点击!2019年9月二级MySQL试题
- T-Sql(七)用户权限操作(grant)
- insightface mxnet训练 旧版
- 冒烟测试与回归测试的区别
- 【MFC】状态栏随对话框的改变而改变
- 让你IDA Pro 快速上手使用
- 多线程不重复读取数据_别再犯错了,多线程访问同一个资源一定要上锁?
- 留言板JavaScript实现
- matlab mat文件
- django 1.8 官方文档翻译: 1-2-5 编写你的第一个Django应用,第5部分
- 认识队列技术中的硬件队列和软件队列及如何改变硬件队列长度
- “我创业成功的十大秘诀”
- Java堆分配参数总结
- 二维光子晶体带隙仿真Matlab完全程序_平面波展开法
- 蓝宝石(Al2O3)晶体基片
- 如何设置苹果Mac菜单栏的时间与日期显示
- XTTS,又一个值得你重视的Oracle数据库迁移升级利器
- 3月plog:恩墨er的DNA动了
- 台式计算机最强配置,台式电脑最好的配置单 台式电脑最好的配置单是怎样的...
- 自然语言处理之机器智能
热门文章
- 攻防世界 ics-05
- Echarts 实现环状半圆形饼图
- 遥感影像的特征空间图
- 微信小程序实现自动语音功能:小程序语音提醒演示
- 代码的坏味道之二十一 :Refused Bequest(被拒绝的遗贈)
- 【练习】Building a Hypermedia-Driven RESTful Web Service
- JavaScript中的事件
- Activiti6--入门学习--中间事件
- 年度网络购物十大被投诉网站淘宝、当当位居前二正文
- linux命令(3) 链接ln和搜索locate,find, whereis, which, grep命令