Forum

How to get the microphone raw data

Hi, There.

I'm planning to develop a voice record web app.

However I can't find webos API to get audio steam data via microphone.

And then, I refer to below URL.

Below is my test code.

    function hasGetUserMedia() {
        return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
            navigator.mozGetUserMedia || navigator.msGetUserMedia);
    }

    if (hasGetUserMedia()) {
        console.log('getUserMedia() is supported in your browser');
        navigator.mediaDevices.getUserMedia({ audio: true, video: false })
            .then(function(stream) {
                console.log('successCallback');
            })
            .catch(function(err) {
                console.log('failureCallback');
            });

    } else {
        console.log('getUserMedia() is not supported in your browser');
    }

    navigator.permissions.query({ name: 'microphone' }).then(function(result) {
        if (result.state == 'granted') {
            console.log('permissions granted');
        } else if (result.state == 'prompt') {
            console.log('permissions prompt');
        } else if (result.state == 'denied') {
            console.log('permissions denied');
        }
        result.onchange = function() {

        };
    });

When I launched test app, I got console log as below.

getUserMedia() is supported in your browser
permissions denied
failureCallback

I guess getUserMedia() API can't run on webOS OSE and I need to add microphone permission.

Could you help me?

Hi @youngyun,

We don't have any API to record audio data via mic.
Instead, you can use below pulseaudio utility to record audio data through mic.

parecord /tmp/rec_file.wav --device=precord

Thanks!