从Java连接两个WAV文件? [英] Join two WAV files from Java?

查看:118
本文介绍了从Java连接两个WAV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是串联在Java 1.6的2 WAV文件最简单的方法? (相同的频率和所有,没有什么花哨。)

What's the simplest way to concatenate two WAV files in Java 1.6? (Equal frequency and all, nothing fancy.)

(这可能是SOOO简单,但我谷歌福今天对这个问题显得无力。)

(This is probably sooo simple, but my Google-fu seems weak on this subject today.)

推荐答案

下面是准系统code:

Here is the barebones code:

import java.io.File;
import java.io.IOException;
import java.io.SequenceInputStream;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;

public class WavAppender {
    public static void main(String[] args) {
	    String wavFile1 = "D:\\wav1.wav";
	    String wavFile2 = "D:\\wav2.wav";

	    try {
		    AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1));
		    AudioInputStream clip2 = AudioSystem.getAudioInputStream(new File(wavFile2));

		    AudioInputStream appendedFiles = 
                            new AudioInputStream(
                                new SequenceInputStream(clip1, clip2),     
                                clip1.getFormat(), 
                                clip1.getFrameLength() + clip2.getFrameLength());

		    AudioSystem.write(appendedFiles, 
                            AudioFileFormat.Type.WAVE, 
                            new File("D:\\wavAppended.wav"));
	    } catch (Exception e) {
		    e.printStackTrace();
	    }
    }
}

这篇关于从Java连接两个WAV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆