Html HTML5 从默认麦克风捕获音频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15940934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:26:47  来源:igfitidea点击:

HTML5 capture audio from default microphone

htmlaudiocapturemicrophone

提问by abduIntegral

Can somebody help me on how to capture audio from default microphone using HTML5? There are many samples available, but none of them seem to working. I have tried Audio capturing with HTML5As it only works with chrome with flags enabled. but it's getting NavigatorUserMediaError. The video icon on the address bar has a red cross sign and its tooltip says 'this page has been blocked from accessing your camera and microphone'

有人可以帮助我如何使用 HTML5 从默认麦克风捕获音频吗?有许多可用的示例,但它们似乎都不起作用。我尝试过使用 HTML5 进行音频捕获,因为它仅适用于启用了标志的 chrome。但它正在获取 NavigatorUserMediaError。地址栏上的视频图标有一个红十字标志,其工具提示显示“此页面已被阻止访问您的相机和麦克风”

回答by cameronroe

There's some great articles on HTML5 Rocks. This is just one that I pulled. http://updates.html5rocks.com/2012/09/Live-Web-Audio-Input-Enabled

有一些关于 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 );

回答by wrachos

make sure you start the demo from a webserver - simply copy/paste & start from file system won't work - in chrome you never get access to the mic this way.

确保您从网络服务器启动演示 - 简单地复制/粘贴并从文件系统启动是行不通的 - 在 chrome 中,您永远无法以这种方式访问​​麦克风。

回答by Nick Schild

Recently (not sure when) Chrome added the requirement that the page be accessed over SSL to enable getUserMedia.

最近(不确定何时)Chrome 添加了通过 SSL 访问页面以启用 getUserMedia 的要求。