androidjs

Microphone API

Microphone API provide the various functions to interact with microphone. In order to use this API you need to add these permissions to your package.json file.

android.permission.RECORD_AUDIO
android.permission.MODIFY_AUDIO_SETTINGS

The following example shows how to record audio in your app

// In front process (web pages)
<html>
    <head>
        // add androidjs.js to get the API's of `Android JS`.
        <script src = "./assets/ipc/androidjs.js" ></script>
    </head>
    <script>
        window.onload = function(){
            app.microphone.getDevices(function(devices){
                app.microphone.startRecording({audio:{deviceId:{exact: devices[1]}}});
            });
        }
    </script>
</html>

Methods

app.microphone.getDevices(callback)

Starts gathering information about all available audio devices, and calls callback(devices) when finished.

An example of above code:

app.microphone.getDevices(function(devices){
    console.log(devices);
})

app.microphone.startRecording(options)

An example of above code:

app.microphone.startRecording({audio:true);

                        or

app.microphone.getDevices(function(devices){
    app.microphone.startRecording({audio:{deviceId:{exact: devices[1]}}});
});

app.microphone.stopRecording()

An example of above code:

app.microphone.stopRecording();

app.microphone.saveRecording(filepath, filename, options)

An example of above code:

app.microphone.saveRecording('/storage/emulated/0/', 'newAudio1.webm', {type:'audio/webm'})

app.microphone.previewRecording(dom, options)

An example of above code:

// <audio id = "preview" autoplay></audio>
app.camera.previewRecording(document.getElementById('preview'), {type: 'audio/webm'});

app.microphone.getBuffer(options, callback)

An example of above code:

app.microphone.getBuffer({type: 'audio/webm'}, function(buffer){
    ...
});