Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Java录制语音_Java_Audio_Audio Recording_Applet - Fatal编程技术网

用Java录制语音

用Java录制语音,java,audio,audio-recording,applet,Java,Audio,Audio Recording,Applet,我想用Java应用程序录制语音;我猜这将基本上是一个小程序,将运行在客户端。但是我不知道怎么做。。。有什么想法吗?另外,我想播放录制的声音 我听说过Java语音API。你知道这是否有帮助吗?我来晚了,但这里有一些关于捕获音频的官方文档: (这里直接从上面的链接复制了一些示例代码:) 请看:@pingw33n-太复杂,无法理解:(在你们的例子中,我在stopped行中有一个错误,你们能帮助我在4年多前写下这个错误吗?我确实从那个url复制了它,但我假设你们有编译错误?那个stopped变量本质上是

我想用Java应用程序录制语音;我猜这将基本上是一个小程序,将运行在客户端。但是我不知道怎么做。。。有什么想法吗?另外,我想播放录制的声音


我听说过Java语音API。你知道这是否有帮助吗?

我来晚了,但这里有一些关于捕获音频的官方文档:

(这里直接从上面的链接复制了一些示例代码:)


请看:@pingw33n-太复杂,无法理解:(在你们的例子中,我在stopped行中有一个错误,你们能帮助我在4年多前写下这个错误吗?我确实从那个url复制了它,但我假设你们有编译错误?那个
stopped
变量本质上是一个占位符,你们应该在别处设置/创建/维护这个变量,以知道你们是否应该停止录音。所以这对你的案子来说非常特殊。
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);
}