有人可以帮助我使用HTML5从默认麦克风中捕获音频吗? 有许多样本可用,但它们似乎都没有工作。 我试过Audio capturing with HTML5 因为它只适用于启用了标志的chrome。但它得到了NavigatorUserMediaError。地址栏上的视频图标有一个红叉标志,其工具提示显示“此页面已被阻止访问您的相机和麦克风”
答案 0 :(得分:8)
HTML5 Rocks上有一些很棒的文章。这只是我拉的一个。 http://updates.html5rocks.com/2012/09/Live-Web-Audio-Input-Enabled
// success callback when requesting audio input stream
function successCallback(stream) {
var audioContext = new (window.webkitAudioContext)();
// Create an AudioNode from the stream.
var mediaStreamSource = audioContext.createMediaStreamSource( stream );
// Connect it to the destination to hear yourself (or any other node for processing!)
mediaStreamSource.connect( audioContext.destination );
}
function errorCallback() {
console.log("The following error occurred: " + err);
}
navigator.webkitGetUserMedia( {audio:true}, successCallback, errorCallback );
答案 1 :(得分:3)
确保您从网络服务器启动演示 - 只需复制/粘贴&从文件系统开始将无法工作 - 在Chrome中你永远不会以这种方式访问麦克风。
答案 2 :(得分:2)
最近(不确定何时)Chrome添加了通过SSL访问该页面以启用getUserMedia的要求。