HTML5的录音用getUserMedia现在正在使用吗?

use*_*542 16 html javascript html5 google-chrome

我搜索了很多关于getUserMedia的DEMO和例子,但大多数只是摄像头捕获,而不是麦克风.

所以我下载了一些例子并在我自己的计算机上进行了尝试,相机捕捉工作正常,但是当我改变时

navigator.webkitGetUserMedia({video : true},gotStream);
Run Code Online (Sandbox Code Playgroud)

navigator.webkitGetUserMedia({audio : true},gotStream);
Run Code Online (Sandbox Code Playgroud)

浏览器要求我先允许麦克风访问,然后失败

document.getElementById("audio").src = window.webkitURL.createObjectURL(stream); 
Run Code Online (Sandbox Code Playgroud)

消息是:

GET blob:http%3A//localhost/a5077b7e-097a-4281-b444-8c1d3e327eb4 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:getUserMedia_simple_audio_test

我做错什么了吗?或者只有getUserMedia现在可以用于相机?

Der*_*會功夫 10

它目前在Google Chrome中不可用.见问题112367.

你可以在演示中看到它总是会抛出错误说

GET blob:http%3A // whatever.it.is/b0058260-9579-419b-b409-18024ef7c6da 404(未找到)

而且你也不能听麦克风

{
    video: true,
    audio: true
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢 !!我希望它很快就能用于镀铬. (2认同)

小智 5

Chrome Canary目前支持它.您需要在地址栏中键入about:flags,然后启用Web Audio Input.

以下代码将音频输入连接到扬声器.注意反馈!

<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()"/>
Run Code Online (Sandbox Code Playgroud)