与Java录制语音 [英] Record voice with Java

查看:276
本文介绍了与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.

我听说过的Java语音API的。任何想法,如果它可以帮助?

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

推荐答案

我迟到了,但这里有上捕捉音频的官方文档:<一href=\"http://docs.oracle.com/javase/tutorial/sound/capturing.html\">http://docs.oracle.com/javase/tutorial/sound/capturing.html

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

(直接从上面这里的链接复制是一些示例code做到这一点:)

(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);
}

这篇关于与Java录制语音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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