我正在构建一个简单的语音聊天应用程序。我决定使用 NodeJS,但我不明白为什么缓冲区总是空的。
我正在使用https://github.com/mattdiamond/Recorderjs
我的代码如下所示:
var audio_context;
var recorder;
function startUserMedia(stream) {
var input = audio_context.createMediaStreamSource(stream);
input.connect(audio_context.destination);
recorder = new Recorder(input);
}
function process() {
recorder.record();
setTimeout(function() {
recorder.getBuffer(function(data) {
console.log(data);
});
}, 3000);
}
window.onload = function init() {
try {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
window.URL = window.URL || window.webkitURL;
audio_context = new AudioContext;
} catch (e) {
console.log(e);
}
navigator.getUserMedia({audio: true}, startUserMedia);
setTimeout(process, 1500);
};
问题是当执行 getBuffer 回调时,数据总是包含 2 个空数组:(