繁体   English   中英

用Java录制语音

[英]Record voice with Java

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

我听说过Java Speech API。 有什么想法可以提供帮助吗?

我迟到了,但这里有关于捕获音频的官方文档: http//docs.oracle.com/javase/tutorial/sound/capturing.html

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM