Работает ли HTML5 getUserMedia для записи звука?
Я искал много DEMO и примеры о getUserMedia, но большинство из них - только захват камеры, а не микрофон.
Итак, я загрузил несколько примеров и попробовал на своем собственном компьютере, захват камеры - это работа,
Но когда я изменил
navigator.webkitGetUserMedia({video : true},gotStream);
to
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 теперь может работать для камеры?
Ответы
Ответ 1
В настоящее время он недоступен в Google Chrome. См. Проблема 112367.
Вы можете увидеть в демо, он всегда будет вызывать ошибку, говоря
GET blob: http% 3A//whatever.it.is/b0058260-9579-419b-b409-18024ef7c6da 404 (не найдено)
А также вы не можете слушать микрофон либо в
{
video: true,
audio: true
}
Ответ 2
В настоящее время он поддерживается в Chrome Canary. Вам нужно ввести около: flags в адресную строку, а затем включить веб-аудиовход.
Следующий код подключает аудиовход к динамикам. ПОСМОТРЕТЬ НА ОБРАТНАЯ СВЯЗЬ!
<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()"/>
Ответ 3
(извините, я забыл логин, поэтому отправляю с моим правильным именем пользователя...)
В настоящее время он поддерживается в Chrome Canary. Вам нужно ввести about:flags
в адресную строку, а затем включить веб-аудиовход.
Следующий код подключает аудиовход к динамикам. ПОСМОТРЕТЬ НА ОБРАТНАЯ СВЯЗЬ!
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()"/>
Ответ 4
Он работает, вам просто нужно добавить параметр toString
после audio : true
Проверьте эту статью - ссылка