java wav压缩_java 调用lame.exe 将 wav 进行MP3压缩的一些问题

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

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-03-05 10:24

浏览 5286

评论

1 楼

自然而永然

2014-07-31

我运行,结果失败

Warning: unsupported audio format

什么问题

06518c3a0f730e08e7ffc573306f0ee6.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值