java 录制,与Java录制语音

I want to record voice using a Java application; I guess this will be basically an applet that will run on client side. But I don't have any idea of how to do it... any ideas? Also, I want to play the recorded voice.

I have heard of Java Speech API. Any idea if it can help?

解决方案

I am late to the party, but here are the official docs on capturing audio: http://docs.oracle.com/javase/tutorial/sound/capturing.html

(And copied directly from the link above here is some sample code to do it:)

TargetDataLine line;

DataLine.Info info = new DataLine.Info(TargetDataLine.class,

format); // format is an AudioFormat object

if (!AudioSystem.isLineSupported(info)) {

// Handle the error ...

}

// Obtain and open the line.

try {

line = (TargetDataLine) AudioSystem.getLine(info);

line.open(format);

} catch (LineUnavailableException ex) {

// Handle the error ...

}

// Assume that the TargetDataLine, line, has already

// been obtained and opened.

ByteArrayOutputStream out = new ByteArrayOutputStream();

int numBytesRead;

byte[] data = new byte[line.getBufferSize() / 5];

// Begin audio capture.

line.start();

// Here, stopped is a global boolean set by another thread.

while (!stopped) {

// Read the next chunk of data from the TargetDataLine.

numBytesRead = line.read(data, 0, data.length);

// Save this chunk of data.

out.write(data, 0, numBytesRead);

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值