代码:使用SoundTouch生成带特殊音效的音频文件

SoundTouch安装方法见:http://blog.csdn.net/qq354960984/article/details/53201448


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 使用SoundTouch工具生成带特殊音效的音频文件
 *
 * 结果文件下载地址:http://pan.baidu.com/s/1gf9LdmF
 *
 * @author Brook
 *
 */
public class SoundEffectDemo {

    public static void main(String[] args) throws Exception {
        // 机器人
        execCommand("soundstretch4Lame original.mp3 Robot-Highest.mp3 -pitch=11");
        execCommand("soundstretch4Lame original.mp3 Robot-Higher.mp3 -pitch=9");
        execCommand("soundstretch4Lame original.mp3 Robot-High.mp3 -pitch=5");
        execCommand("soundstretch4Lame original.mp3 Robot-Low.mp3 -pitch=-5");
        execCommand("soundstretch4Lame original.mp3 Robot-Lower.mp3 -pitch=-9");
        execCommand("soundstretch4Lame original.mp3 Robot-Lowest.mp3 -pitch=-11");

        // 回声
        execCommand("soundstretch4Lame original.mp3 Echo_-10.mp3 -tempo=-10");
        execCommand("soundstretch4Lame original.mp3 Echo_-30.mp3 -tempo=-30");
        execCommand("soundstretch4Lame original.mp3 Echo_-50.mp3 -tempo=-50");

        // 加速
        execCommand("soundstretch4Lame original.mp3 Speed_-10.mp3 -rate=-10");
        execCommand("soundstretch4Lame original.mp3 Speed_-30.mp3 -rate=-30");
        execCommand("soundstretch4Lame original.mp3 Speed_-50.mp3 -rate=-50");

        // 减速
        execCommand("soundstretch4Lame original.mp3 Speed_10.mp3 -rate=10");
        execCommand("soundstretch4Lame original.mp3 Speed_30.mp3 -rate=30");
        execCommand("soundstretch4Lame original.mp3 Speed_50.mp3 -rate=50");
    }

    /**
     * 执行命令
     * 
     * @param command
     *            命令
     * @return
     */
    public static void execCommand(String command) throws Exception {
        System.out.println("*************start execute command**************");

        BufferedReader br = null;
        Process proc = null;
        try {
            // 创建子进程并执行命令
            proc = Runtime.getRuntime().exec(command);

            // 获取错误流,并打印输出
            br = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println("line: " + line);
            }
            System.out.println("*************execute end**************");
        } catch (Exception t) {
            t.printStackTrace();
            System.out.println("*************execute end**************");
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }

            if (proc != null) {
                proc.destroy();
            }
        }
    }
}

你可能感兴趣的:(Java,音频处理)