日期:2014-05-20 浏览次数:20897 次
try { Process process = Runtime.getRuntime().exec("cmd /c copy 1.wav+2.wav 3.wav"); //调用Ping命令 InputStream in1=new FileInputStream("3.wav"); AudioStream au =new AudioStream(in2); au.player.start(au); //结束后也可以将新的wav删除 }catch (Exception e) { e.printStackTrace(); } }
------解决方案--------------------
linux下:
try { Process process = Runtime.getRuntime().exec("cp>1.wav+2.wav 3.wav"); //调用cp命令 InputStream in1=new FileInputStream("3.wav"); AudioStream au =new AudioStream(in2); au.player.start(au); //结束后也可以将新的wav删除 }catch (Exception e) { e.printStackTrace(); } }
------解决方案--------------------
import javax.sound.sampled.*;
file = new File("XXXX.WAV");
issoundfirst = true;
try
{
stream = (AudioInputStream)AudioSystem.
getAudioInputStream(
file);
AudioFormat format = stream.getFormat();
if((format.getEncoding() == AudioFormat.Encoding.ULAW) ||
(format.getEncoding() == AudioFormat.Encoding.ALAW))
{
AudioFormat tmp = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits() * 2,
format.getChannels(),
format.getFrameSize() * 2,
format.getFrameRate(),
true);
stream = AudioSystem.getAudioInputStream(tmp,stream);
format = tmp;
}
DataLine.Info info = new DataLine.Info(
Clip.class,
stream.getFormat(),
((int)stream.getFrameLength() *
format.getFrameSize()));
clip = (Clip)AudioSystem.getLine(info);
clip.open(stream);
clip.start();
while(clip.isActive())
{
}
clip.stop();
clip.close();
}