使用场景:
业务中需要使用微信语音接口,由于微信上传语音只保存3天,所以需要将语音文件下载到服务器。
但是amr格式文件,前端无法识别,需要将其转换为mp3格式。
装换方法如下:
1、需安装ffmpeg软件(安装方法自行百度)
2、转换代码:
public static boolean amrToMp3(String localPath, String targetFilePath) {
try {
java.lang.Runtime rt = Runtime.getRuntime();
String command = \"ffmpeg -i \" + localPath + \" \" + targetFilePath;
System.out.println(\"command = \" + command);
Process proc = rt.exec(command);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(\"ffmpeg Process errorInfo: \" + sb.toString());
int exitVal = proc.waitFor();
System.out.println(\"ffmpeg Process exitValue: \" + exitVal);
return true;
} catch (Exception e) {
System.out.println(\"ffmpeg exec cmd Exception \" + e.toString());
}
return false;
}
继续阅读与本文标签相同的文章
下一篇 :
Excel如何跨表求和?3款技巧总有一款适合你
-
充电宝逆袭共享单车,打脸王思聪?大家都打错脸了,事实并非如此
2026-05-19栏目: 教程
-
余承东说到做到,华为开启“全力反击”模式,谷歌始料未及!
2026-05-19栏目: 教程
-
等了 1 个多月,我就自己动手了
2026-05-19栏目: 教程
-
使用 Docker 构建 Nebula Graph 源码
2026-05-19栏目: 教程
-
阿里云服务器机型价格及如何选择?
2026-05-19栏目: 教程
