javascript 用于录音的 HTML5 的 getUserMedia 现在是否有效?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10791457/
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
Is HTML5's getUserMedia for audio recording working now?
提问by user1422542
I had searched a lot of DEMO and examples about getUserMedia , but most are just camera capturing, not microphone.
我搜索了很多关于 getUserMedia 的 DEMO 和示例,但大多数只是相机捕获,而不是麦克风。
So I downloaded some examples and tried on my own computer , camera capturing is work , But when I changed
所以我下载了一些例子并在我自己的电脑上尝试,相机捕获是有效的,但是当我改变时
navigator.webkitGetUserMedia({video : true},gotStream);
to
到
navigator.webkitGetUserMedia({audio : true},gotStream);
The browser ask me to allow microphone access first, and then it failed at
浏览器首先要求我允许麦克风访问,然后它在
document.getElementById("audio").src = window.webkitURL.createObjectURL(stream);
The message is :
消息是:
GET blob:http%3A//localhost/a5077b7e-097a-4281-b444-8c1d3e327eb4 404 (Not Found)
This is my code: getUserMedia_simple_audio_test
这是我的代码:getUserMedia_simple_audio_test
Did I do something wrong? Or only getUserMedia can work for camera now ?
我做错什么了吗?或者现在只有 getUserMedia 可以用于相机?
采纳答案by u283863
It is currently not available in Google Chrome. See Issue 112367.
它目前在 Google Chrome 中不可用。请参阅问题 112367。
You can see in the demo, it will always throw an error saying
你可以在演示中看到,它总是会抛出一个错误说
GET blob:http%3A//whatever.it.is/b0058260-9579-419b-b409-18024ef7c6da 404 (Not Found)
GET blob:http%3A//whatever.it.is/b0058260-9579-419b-b409-18024ef7c6da 404(未找到)
And also you can't listen to the microphone either in
而且你也不能听麦克风
{
video: true,
audio: true
}
回答by Matthew Yee-King
It is currently supported in Chrome Canary. You need to type about:flags into the address bar then enable Web Audio Input.
Chrome Canary 目前支持它。您需要在地址栏中输入 about:flags,然后启用 Web Audio Input。
The following code connects the audio input to the speakers. WATCH OUT FOR THE FEEDBACK!
以下代码将音频输入连接到扬声器。注意反馈!
<script>
// this is to store a reference to the input so we can kill it later
var liveSource;
// creates an audiocontext and hooks up the audio input
function connectAudioInToSpeakers(){
var context = new webkitAudioContext();
navigator.webkitGetUserMedia({audio: true}, function(stream) {
console.log("Connected live audio input");
liveSource = context.createMediaStreamSource(stream);
liveSource.connect(context.destination);
});
}
// disconnects the audio input
function makeItStop(){
console.log("killing audio!");
liveSource.disconnect();
}
// run this when the page loads
connectAudioInToSpeakers();
</script>
<input type="button" value="please make it stop!" onclick="makeItStop()"/>
回答by yeeking
(sorry, I forgot to login, so posting with my proper username...)
(对不起,我忘记登录了,所以用我正确的用户名发帖......)
It is currently supported in Chrome Canary. You need to type about:flags
into the address bar then enable Web Audio Input.
Chrome Canary 目前支持它。您需要about:flags
在地址栏中输入,然后启用 Web 音频输入。
The following code connects the audio input to the speakers. WATCH OUT FOR THE FEEDBACK!
以下代码将音频输入连接到扬声器。注意反馈!
<script>
// this is to store a reference to the input so we can kill it later
var liveSource;
// creates an audiocontext and hooks up the audio input
function connectAudioInToSpeakers(){
var context = new webkitAudioContext();
navigator.webkitGetUserMedia({audio: true}, function(stream) {
console.log("Connected live audio input");
liveSource = context.createMediaStreamSource(stream);
liveSource.connect(context.destination);
});
}
// disconnects the audio input
function makeItStop(){
console.log("killing audio!");
liveSource.disconnect();
}
// run this when the page loads
connectAudioInToSpeakers();
</script>
<input type="button" value="please make it stop!" onclick="makeItStop()"/>