package com.city.controller.commnons;
import java.io.File;
import org.apache.log4j.Logger;
/**
* @ClassName:
* @package:
* @Description:
* @author: guoran
* @Create Date: 20171213
* @Mail : grprogram@163.com
* @Version: V1.01 (版本号)
* @Modified by:
*
*/
public class RecordUtils {
//private static logger logger = Logger.getLogger(RecordUtils.class);
private static Logger logger = Logger.getLogger(RecordUtils.class);
/**
* 将上传的录音转为mp3格式
*
* @param webroot
* 项目的根目录
* @param sourcePath
* 文件的相对地址
*/
public static void ToAMR(String webroot, String originalName) {
// File file = new File(sourcePath);
String sourcePath = webroot + originalName;
String targetPath = webroot + originalName.substring(0, originalName.lastIndexOf(".")) + ".amr";// 转换后文件的存储地址,直接将原来的文件名后加mp3后缀名
//此判断是为了解决ffmpeg插件在包含有空格的时候无法转换音频文件的bug
if (sourcePath.indexOf(" ") > 0) {
sourcePath = "\"" + sourcePath + "\"";
}
if (targetPath.indexOf(" ") > 0) {
targetPath = "\"" + targetPath + "\"";
}
logger.info("ffmpeg targetPath:" + "===>" + targetPath);
logger.info("ffmpeg sourcePath:" + "===>" + sourcePath);
Runtime run = null;
try {
run = Runtime.getRuntime();
long start = System.currentTimeMillis();
Process p = run.exec(webroot + "ffmpeg -i " + sourcePath + " -ar 8000 -ab 12.2k -ac 1 " + targetPath);// 执行ffmpeg.exe,前面是ffmpeg.exe的地址,中间是需要转换的文件地址,后面是转换后的文件地址。-i是转换方式,意思是可编码解码,mp3编码方式采用的是libmp3lame
// 释放进程
p.getOutputStream().close();
p.getInputStream().close();
p.getErrorStream().close();
p.waitFor();
long end = System.currentTimeMillis();
logger.info(sourcePath + " convert success, costs:" + (end - start) + "ms");
File file = new File(webroot + targetPath);
// 删除原来的文件
if (file.exists()) {
logger.info("转换文件" + file.getAbsolutePath() + "成功");
}
} catch (Exception e) {
logger.error("ffmpeg convert error:" + e.getMessage());
} finally {
// run调用lame解码器最后释放内存
run.freeMemory();
}
}
public static void ToAMR(String ffmpegPath, String sourcePath, String targetPath) {
if (sourcePath.indexOf(" ") > 0) {
sourcePath = "\"" + sourcePath + "\"";
}
if (targetPath.indexOf(" ") > 0) {
targetPath = "\"" + targetPath + "\"";
}
logger.info("ffmpeg targetPath:" + "===>" + targetPath);
logger.info("ffmpeg sourcePath:" + "===>" + sourcePath);
Runtime run = null;
try {
run = Runtime.getRuntime();
long start = System.currentTimeMillis();
Process p = run.exec(ffmpegPath + "ffmpeg -i " + sourcePath + " -ar 8000 -ab 12.2k -ac 1 " + targetPath);// 执行ffmpeg.exe,前面是ffmpeg.exe的地址,中间是需要转换的文件地址,后面是转换后的文件地址。-i是转换方式,意思是可编码解码,mp3编码方式采用的是libmp3lame
// 释放进程
p.getOutputStream().close();
p.getInputStream().close();
p.getErrorStream().close();
p.waitFor();
long end = System.currentTimeMillis();
logger.info(sourcePath + " convert success, costs:" + (end - start) + "ms");
// 删除原来的文件
// if(file.exists()){
// file.delete();
// }
} catch (Exception e) {
logger.error("ffmpeg convert error:" + e.getMessage());
} finally {
// run调用lame解码器最后释放内存
run.freeMemory();
}
}
public static void main(String[] args) {
ToAMR("D:/Program Files/Test/", "D:/Program Files/Test/abcdefg.wav", "D:/Program Files/Test/abcdefg.amr");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Html5和FlashWavRecorder两种实现浏览器录制wav音频和上传音频文件
共70个文件
jar:12个
xml:8个
js:7个
2星 需积分: 50 92 下载量 96 浏览量
2017-12-13
16:59:46
上传
评论
收藏 13.57MB RAR 举报
温馨提示
Html5和FlashWavRecorder两种实现浏览器录制wav音频和上传音频文件,其中包含 Html5录音、FlashWavRecorder、音频转换、springMVC,不包含数据库,直接跑起来
资源推荐
资源详情
资源评论
收起资源包目录
record.rar (70个子文件)
record
.project 1KB
pom.xml 2KB
target
test-classes
maven-archiver
pom.properties 121B
maven-status
maven-compiler-plugin
compile
default-compile
createdFiles.lst 48B
inputFiles.lst 92B
testCompile
default-testCompile
inputFiles.lst 0B
m2e-wtp
web-resources
META-INF
maven
com.test
record
pom.xml 2KB
pom.properties 213B
MANIFEST.MF 105B
HelloSpringMVC
WEB-INF
views
hellospring.jsp 466B
web.xml 1KB
lib
javax.servlet-api-3.1.0.jar 94KB
spring-webmvc-4.1.1.RELEASE.jar 757KB
spring-expression-4.1.1.RELEASE.jar 244KB
spring-web-4.1.1.RELEASE.jar 684KB
spring-context-4.1.1.RELEASE.jar 1003KB
commons-logging-1.1.3.jar 61KB
spring-core-4.1.1.RELEASE.jar 981KB
spring-beans-4.1.1.RELEASE.jar 687KB
aopalliance-1.0.jar 4KB
spring-aop-4.1.1.RELEASE.jar 351KB
classes
com
city
controller
HelloSpringController.class 1KB
spring-mvc-servlet.xml 1KB
index.jsp 502B
META-INF
classes
log4j.properties 997B
com
city
controller
UploadServlet.class 3KB
UploadServletNew.class 4KB
HelloSpringController.class 1KB
commnons
RecordUtils.class 4KB
spring-mvc-servlet.xml 1KB
HelloSpringMVC.war 4.22MB
.settings
.jsdtscope 639B
org.eclipse.core.resources.prefs 162B
org.eclipse.wst.common.component 629B
org.eclipse.wst.validation.prefs 50B
org.eclipse.jdt.core.prefs 736B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.jsdt.ui.superType.name 6B
src
test
java
main
resources
log4j.properties 997B
spring-mvc-servlet.xml 1KB
java
com
city
controller
UploadServlet.java 3KB
UploadServletNew.java 3KB
HelloSpringController.java 1KB
commnons
RecordUtils.java 4KB
webapp
css
uploadstyle.css 2KB
recorder.swf 18KB
WEB-INF
views
hellospring.jsp 466B
web.xml 2KB
index.jsp 506B
uploadfile.jsp 4KB
audio
upload
record
ffmpeg.exe 11.74MB
images
record.png 350B
play.png 238B
pause.png 322B
upload.png 402B
stop.png 333B
js
recordmp3.js 5KB
worker-realtime.js 2KB
swfobject.js 10KB
main.js 6KB
recorder.js 5KB
lame.min.js 153KB
jquery.js 160KB
uploadfilenew.jsp 5KB
WebContent
WEB-INF
lib
mybatis-3.2.7.jar 696KB
sqljdbc4.jar 571KB
META-INF
MANIFEST.MF 39B
.classpath 1KB
共 70 条
- 1
资源评论
- 霸都王大炮2018-02-27项目跑不起来
- qq_288318172018-05-13还可以,不错谷歌浏览器欧朋浏览器不支持
二然子
- 粉丝: 9
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于python和opencv的样本交互标注工具+源码+文档说明(期末大作业&课程设计&项目开发)
- IMG_20240329_150532.jpg
- 《电路》大作业:基于matlab实现的节点电压法计算+源代码+文档说明
- 3401-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- Mysql 版中国省市区数据表SQL
- 数值分析,基于MATLAB GUI 的“数值分析方法”计算器+源代码+文档说明
- 基于matlab水果识别系统代码32gui界面设计
- 基于Python大规模文本分析系统的开题报告.docx
- 3401-CMN3401-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- python实现的四则运算计算器
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功