语音amr文件转换为mp3文件
1.安卓前端生成amr语音文件,经过base64加密变成加密字符串
2.把加密后的字符串解密成amr文件
生成amr文件目录
String fileUrl = System.getProperty("user.dir").replace(
"bin", "webapps")
+ File.separator
+ "wfCloudRes"
+ File.separator
+ "image"
+ File.separator
+ dateStr
+ File.separator + "topic" + File.separator + maxId;
public static String base64ToIo(String strBase64,String fileUrl) throws IOException {
String string = strBase64;
String fileName = fileUrl+File.separator+"audio.amr";
String saveDir = fileUrl;
File dir = new File(saveDir);
if(!dir.exists()){
dir.mkdirs();
}
try {
// 解码,然后将字节转换为文件
byte[] bytes = new BASE64Decoder().decodeBuffer(string); // 将字符串转换为byte数组
FileOutputStream out = new FileOutputStream(fileName);
out.write(bytes);
out.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return fileName;
}
3.amr文件转换为MP3文件
这个转化要使用第三方的jar包jave-1.0.2.jar
http://www.sauronsoftware.it/projects/jave/download.php
// mp3文件目录
String fileTargetUrl = System.getProperty("user.dir")
.replace("bin", "webapps")
+ File.separator
+ "wfCloudRes"
+ File.separator
+ "image"
+ File.separator
+ dateStr
+ File.separator
+ "topic"
+ File.separator
+ maxId
+ File.separator + "audio.mp3";
public static void changeToMp3(String sourcePath, String targetPath) {
File source = new File(sourcePath);
File target = new File(targetPath);
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
// audio.setBitRate(new Integer(64000));
// audio.setChannels(new Integer(2));
// audio.setSamplingRate(new Integer(22050));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
try {
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InputFormatException e) {
e.printStackTrace();
} catch (EncoderException e) {
e.printStackTrace();
}
}
4.删除amr文件
FileUtils.deleteFile(fileUrl, "amr");
public static boolean deleteFile(String path, String suffixType) {
boolean flag = false;
if (StringUtils.isEmpty(path)) {
return flag;
}
File file = new File(path);// 里面输入特定目录
File temp = null;
File[] filelist = file.listFiles();
for (int i = 0; i < filelist.length; i++) {
temp = filelist[i];
if (temp.getName().endsWith(suffixType)) {// 获得文件名,如果后缀为“”,这个你自己写,就删除文件
temp.delete();// 删除文件
flag = true;
}
}
return flag;
}
Base64加密和解密工具类
mport java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Base64Utils {
public static void main(String[] args) throws Exception {
// String strBase64 = Base64Utils.ioToBase64("d:/bubugao.amr"); // 将 io 转换为 base64编码
// System.out.println(">>> " + strBase64);
// System.out.println(Base64Utils.base64ToIo(strBase64,"d:/bubugao.mp3")); // 将 base64编码转换为
// 文件流,生成一幅新图片
// System.out.println(Base64Utils.encodeBase64File("d:/bubugao.amr"));
}
public static String ioToBase64(String path) throws IOException {
// String fileName = "D:/u18.jpg"; // 源文件
String source = path;
String strBase64 = null;
try {
InputStream in = new FileInputStream(source);
// in.available()返回文件的字节长度
byte[] bytes = new byte[in.available()];
// 将文件中的内容读入到数组中
in.read(bytes);
strBase64 = new BASE64Encoder().encode(bytes); // 将字节流数组转换为字符串
in.close();
} catch (FileNotFoundException fe) {
fe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return strBase64;
}
public static String base64ToIo(String strBase64,String fileUrl) throws IOException {
String string = strBase64;
String fileName = fileUrl+File.separator+"audio.amr";
String saveDir = fileUrl;
File dir = new File(saveDir);
if(!dir.exists()){
dir.mkdirs();
}
try {
// 解码,然后将字节转换为文件
byte[] bytes = new BASE64Decoder().decodeBuffer(string); // 将字符串转换为byte数组
FileOutputStream out = new FileOutputStream(fileName);
out.write(bytes);
out.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return fileName;
}
}
文件转换类的代码如下:
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.InputFormatException;
import java.io.File;
public class Mp3Convert {
public static void changeToMp3(String sourcePath, String targetPath) {
File source = new File(sourcePath);
File target = new File(targetPath);
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
// audio.setBitRate(new Integer(64000));
// audio.setChannels(new Integer(2));
// audio.setSamplingRate(new Integer(22050));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
try {
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InputFormatException e) {
e.printStackTrace();
} catch (EncoderException e) {
e.printStackTrace();
}
}
}
语音amr文件转换为mp3文件相关推荐
- 如何将微信amr文件转换为mp3文件
本篇经验将介绍,如何将微信的amr文件转换为mp3文件. 工具/原料 电脑 电脑软件:silk2mp3 amr文件 方法/步骤 下载软件,解压. 进入以下目录,打开软件. silk-v3-decode ...
- linux java amr转mp3_本工具用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放...
音频转码工具 本工具主要用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放. 支持 Linux/Windows/Mac 平台 因为是基于 JAVE 项目 ...
- java amr音频转码_jave: 音频转码工具,主要用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放...
音频转码工具 本工具主要用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放. 支持 Linux/Windows/Mac 平台 因为是基于 JAVE 项目 ...
- android 视频转音频,将mp4文件转换为mp3文件的方法
很多文章关于将MP4转为MP3写的都很复杂,我这里总结一个比较简单的方法.此方法有个BUG,最后再说.但整体功能比较简单可用. 一,导入第三方文件 此方法用到3个第三方库文件如下,(资源和Demo在文 ...
- 使用Python把flv格式的文件转换为mp3格式
目的:想把喜欢视频转换为音频,在手机上听 以下的是转换的关键代码,首先要确保moviepy库是安装成功了. import moviepy.editor as mpif __name__ == &quo ...
- PHP如何下载微信语音到服务器,并将amr格式转换为MP3格式,最后上传到阿里云oss文件中
第一步:下载微信语音到服务器中 废话不多说,直接上代码 1.总的流程方法(里面的方法在下面) 2.下载微信语音的方法 3.将微信语音的amr格式转换为MP3格式(需要使用FFmpeg,安装使用过程请看 ...
- php将amr转换成mp3,微信JSSDK-将录制文件amr格式转换为mp3
前言: 作者最近基于类似于微信聊天的长按通话功能开发了一个微信公众号. 在这里 开发环境: centos 7.4 前端将录制数据serverId(返回的音频的服务器ID)传递给后端,后端使用下面的接口 ...
- PHP 将amr音频文件转换为mp3格式
PHP 将amr音频文件转换为mp3格式 说下整体思路 1.服务器安装ffmpeg 2.使用ffmpeg -i 指令来转换amr为mp3格式(这个到时候写在PHP代码中,使用exec函数执行即可) 3 ...
- 快速转换:将音乐文件转换为MP3格式的步骤
如果你有一个音乐文件,但它的格式不是MP3,你可能需要将其转换为MP3格式,这样它就可以被更广泛地播放和共享.下面是一些步骤,帮助你快速将音乐文件转换为MP3格式. 1.下载并安装一个音频转换软件.有 ...
最新文章
- java中是什么意思_java中是什么意思?
- 《阿里巴巴数据中台实践》深入理解
- LeetCode 网易-1. 分割环(前缀和 + 哈希)
- JAVA并发,线程异常捕获
- 事物与持久化_DDD之聚合持久化应该怎么做?
- 如何在Eclipse配置Tomcat
- 如果粒子运动只受力影响,那么意识从何而来
- 根据Excel记录生成Mysql和Hive建表语句
- 趣头条的区块链实验:为何金币贬值了6.6倍?
- STAP旁瓣干扰抑制与干扰对抗仿真
- ae中计算机打字预设,Typewriter Pro(AE电脑打字动画特效预设)
- Mysql查看表的数据量
- quickBI数据脱敏
- vs = VirtualService
- miniui展示日历能点击_南怀瑾先生2021日历,人生难题问南师!
- 幼儿园大班20以内加减法Excel公式
- 相对论通俗演义(1-10) 第九章
- 【研究】移动办公趋势洞察系列之二:人工智能、智能硬件精彩纷呈,业务协同初心不变
- 【Jetson-Nano】jetson_nano安装环境配置及tensorflow和pytorch的安装
- 华为路由器AR2240