2012-05-28 63 views
16

我已經搜索了很多關於getUserMedia的DEMO和示例,但大多數只是相機捕獲,而不是麥克風。現在HTML5的getUserMedia用於錄音嗎?

於是我下載了一些例子,盡我自己的電腦上,攝像頭捕捉的工作, 但是當我改變

navigator.webkitGetUserMedia({video : true},gotStream); 

navigator.webkitGetUserMedia({audio : true},gotStream); 

瀏覽器問我,讓麥克風接入第一,然後失敗

document.getElementById("audio").src = window.webkitURL.createObjectURL(stream); 

亂七八糟的年齡:

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

這是我的代碼:getUserMedia_simple_audio_test

難道我做錯了什麼?或者只有getUserMedia現在可以用於相機?

+0

即使你把[' 「視頻,音頻」',它(http://jsfiddle.net/DerekL/JV996/)仍然不會得到'audio'部分(如果你已經注意到了。) –

+0

在鉻版本19中,'xxx'工作。但在版本21中,只有{xxx:true}有效,這是我在更新chrome後發現的。 – user1422542

回答

10

它目前在Google Chrome中不可用。見Issue 112367

你可以看到the demo,它總是會拋出一個錯誤說

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

,你也可以不聽話筒無論是在

{ 
    video: true, 
    audio: true 
} 
+2

謝謝!我希望它很快就會在Chrome中可用。 – user1422542

0

它的工作,你只需要後添加toString參數

檢查這篇文章 - link

+3

'toString'這個東西是一種破解,它可以一起支持舊的參數格式(''video',audio'')和新格式('{video:true,audio:true}')。在Chrome中,音頻還沒有實現,所以沒有任何「技巧」讓它突然工作。 – pimvdb

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()"/> 
+0

我不認爲這是...音頻播放形式麥克風是的; (並且只在mac中使用chrome;而chrome canary)但錄音?不要以爲這是可能的。 – Thomas

1

(對不起,我忘了登錄,我的正確的用戶名...所以發佈)

這是目前在Chrome金絲雀支持。您需要在地址欄中輸入about:flags,然後啓用Web音頻輸入。

以下代碼將音頻輸入連接到揚聲器。注意反饋!

http://jsfiddle.net/2mLtM/

<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()"/>