在Java中开始录制操作时,如何检测静音?什么是PCM数据?如何在Java中计算PCM数据?
我找到了解决方案:
package bemukan.voiceRecognition.speechToText;
import javax.sound.sampled.*;
import java.io.*;
public class RecordAudio {
private File audioFile;
protected boolean running;
private ByteArrayOutputStream out;
private AudioInputStream inputStream;
final static float MAX_8_BITS_SIGNED = Byte.MAX_VALUE;
final static float MAX_8_BITS_UNSIGNED = 0xff;
final static float MAX_16_BITS_SIGNED = Short.MAX_VALUE;
final static float MAX_16_BITS_UNSIGNED = 0xffff;
private AudioFormat format;
private float level;
private int frameSize;
public RecordAudio(){
getFormat();
}
private AudioFormat getFormat() {
File file = new File("src/Facebook/1.wav");
AudioInputStream stream;
try {
stream = AudioSystem.getAudioInputStream(file);
format=stream.getFormat();
frameSize=stream.getFormat().getFrameSize();
return …Run Code Online (Sandbox Code Playgroud) 我正在使用带有NodeJS后端的Google Cloud API for Speech-to-text.应用程序需要能够侦听语音命令,并将它们作为缓冲区传输到后端.为此,我需要在检测到静音时发送前一个音频的缓冲区.
任何帮助,将不胜感激.包括下面的js代码
if (!navigator.getUserMedia)
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true}, success, function (e) {
alert('Error capturing audio.');
});
} else alert('getUserMedia not supported in this browser.');
var recording = false;
window.startRecording = function () {
recording = true;
};
window.stopRecording = function () {
recording = false;
// window.Stream.end();
};
function success(e) {
audioContext = window.AudioContext || window.webkitAudioContext;
context = new audioContext();
// the sample rate is in …Run Code Online (Sandbox Code Playgroud) javascript node.js audiocontext web-audio-api google-cloud-speech
我有一个使用MediaRecorderapi 创建的音频文件/ blob :
let recorder = new MediaRecorder(this.stream)
let data = [];
recorder.ondataavailable = event => data.push(event.data);
Run Code Online (Sandbox Code Playgroud)
然后在录制结束时:
let superBlob = new Blob(data, { type: "video/webm" });
Run Code Online (Sandbox Code Playgroud)
如何使用此blob创建AudioBuffer?我需要:
Blob对象转换为ArrayBuffer我可以使用的对象AudioContext.decodeAudioData(返回一个AudioBuffer)或Blob对象转换为a Float32Array,我可以将其复制到AudioBufferwith中AudioBuffer.copyToChannel()任何关于如何实现这一点的提示都表示赞赏.干杯!