【发布时间】:2013-12-06 00:12:16
【问题描述】:
我正在构建一个简单的语音聊天应用。我决定使用 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 个空数组:(
【问题讨论】:
-
从您在答案中包含的图片中,有一条消息“资源解释为脚本,但使用 MIME 类型文本/纯文本传输。”。你必须正确配置你的服务器,查看Chrome says “Resource interpreted as script but transferred with MIME type text/plain.”, what gives?的答案
-
遗憾的是这不是问题。
标签: javascript audio buffer html5-audio recorder