Audio Recording(Accessing microphone) using HTML5 in mobile browsers

androidDev picture androidDev · Jan 21, 2013 · Viewed 7.7k times · Source

Can we access microphone of mobile to record our voice using HTML5?

I was trying this link:

http://www.html5rocks.com/en/tutorials/getusermedia/intro/

where I get

< input type="file" accept="audio/*;capture=microphone">

I used the following input tag to access microphone but it didnt worked in the HTML viewer of device.

Please help.

Thanks in advance.

Answer

David Storey picture David Storey · May 17, 2013

Which browser are you using? You can use getUserMedia rather than input type="file". This demos works in Chrome desktop: http://jsfiddle.net/GD63T/2/ but to work in Chrome for android you have to turn it on using chrome://flags

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||     navigator.mozGetUserMedia || navigator.msGetUserMedia;

var audio = document.querySelector('audio');

if (navigator.getUserMedia) {
    navigator.getUserMedia({
        audio: true,
        video: false
    }, function (stream) {
       audio.src = window.URL.createObjectURL(stream);
    }, onFailSoHard);
} else {
    alert("sorry, not supported in your browser");
}