package xm.createpkg;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class AudioImpress {
/**
* 转化单个文件
* @param path
* @return
*/
public static String singleShell(String path) {
String newName = path.replace(“.wav”, “.mp3”);
String command = “d:\\lame -V2 ” + path + ” ” + newName;
try {
String cmd = createBat(command);
Process process = Runtime.getRuntime().exec(cmd);
final InputStream is1 = process.getInputStream();
final InputStream is2 = process.getErrorStream();
new Thread() {
public void run() {
BufferedReader br = new BufferedReader(
new InputStreamReader(is1));
try {
String lineB = null;
while ((lineB = br.readLine()) != null) {
if (lineB != null) System.out.println(lineB);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
new Thread() {
public void run() {
BufferedReader br2 = new BufferedReader(
new InputStreamReader(is2));
try {
String lineC = null;
while ((lineC = br2.readLine()) != null) {
if (lineC != null) System.out.println(lineC);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
process.waitFor();
} catch (Throwable e) {
e.printStackTrace();
}
return newName;
}
/**
* 转化一个文件下所以文件,包括n层文件夹
* @param strList
*/
private static void callShell(List strList) {
try {
for (int i = 0; i < strList.size(); i++) {
String newName = strList.get(i).replace(“.wav”, “.mp3”);
String command = “d:\\lame -V2 ” + strList.get(i) + ” “
+ newName;
String cmd = createBat(command);
Process process = Runtime.getRuntime().exec(cmd);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
private static String createBat(String command) throws IOException {
String dir = “d:\\lame.bat”;
byte[] b = command.getBytes();
File file = new File(dir);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream os = new FileOutputStream(file);
os.write(b);
os.close();
return dir;
}
private static List getFileName(String path, List strList) {
File file = new File(path);
FileFilter ff = new FileFilter() {
@Override
public boolean accept(File dir) {
if (dir.getName().endsWith(“.wav”)) {
return true;
}
return false;
}
};
if (file.isFile()) {
System.out.println(“必须是文件夹”);
} else {
File[] fileList = file.listFiles(ff);
for (File f : fileList) {
if (f.isFile()) {
strList.add(f.getAbsolutePath());
} else {
getFileName(f.getAbsolutePath(), strList);
}
}
}
return strList;
}
public static void main(String[] args) throws IOException {
String path = “G:\\本人文档存放\\研发中心任务文档\\自动分析html\\colorblock-音效文件\\audio\\20114822174851.wav”;
// change(path);
//AudioImpress ai = new AudioImpress();
singleShell(path);
//CreatePkg pkg = new CreatePkg();
//pkg.audioImpress(path);
}
private static void change(String path) {
List strList = new ArrayList();
getFileName(path, strList);
callShell(strList);
}
}
lame.zip (158.2 KB)
下载次数: 95
分享到:
2012-03-05 10:24
浏览 5286
评论
1 楼
自然而永然
2014-07-31
我运行,结果失败
Warning: unsupported audio format
什么问题
今天的文章java wav压缩_java 调用lame.exe 将 wav 进行MP3压缩的一些问题分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/26501.html