项目要求:
开发龟兔赛跑的多媒体版本,可以录制比赛播音员的声音:如“运动员站在起跑线上”,“他们出发了!”,“兔子领先!”,“乌龟赶上来了!”等等。在比赛进行时播放录制好的声
音,同时播放一些模拟动物跑步的声音,还有观众加油的声音,最后动画动物在高山上赛跑的图象。 兄弟们,现在主要要实现的是用java录音的功能,播放的功能已经可以实现拉,那位用java做过录音功能的例子,帮楼主给点建议,谢谢!
开发龟兔赛跑的多媒体版本,可以录制比赛播音员的声音:如“运动员站在起跑线上”,“他们出发了!”,“兔子领先!”,“乌龟赶上来了!”等等。在比赛进行时播放录制好的声
音,同时播放一些模拟动物跑步的声音,还有观众加油的声音,最后动画动物在高山上赛跑的图象。 兄弟们,现在主要要实现的是用java录音的功能,播放的功能已经可以实现拉,那位用java做过录音功能的例子,帮楼主给点建议,谢谢!
import javax.sound.sampled.*;
import java.net.*; class Capture implements Runnable { TargetDataLine line;
Thread thread;
Socket s;
BufferedOutputStream captrueOutputStream; Capture(Socket s){
this.s=s;
} public void start() { thread = new Thread(this);
thread.setName("Capture");
thread.start();
} public void stop() {
thread = null;
} public void run() { try {
captrueOutputStream=new BufferedOutputStream(s.getOutputStream());
}
catch (IOException ex) {
return;
} AudioFormat format =new AudioFormat(8000,16,2,true,true);//AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
DataLine.Info info = new DataLine.Info(TargetDataLine.class,format); try {
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format, line.getBufferSize());
} catch (Exception ex) {
return;
} byte[] data = new byte[1024];
int numBytesRead=0;
line.start(); while (thread != null) {
numBytesRead = line.read(data, 0,1024);
try {
captrueOutputStream.write(data, 0, numBytesRead);
}
catch (Exception ex) {
break;
}
} line.stop();
line.close();
line = null; try {
captrueOutputStream.flush();
captrueOutputStream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
缺了个main吧!
有没有录音这方面的介绍啊~~~