Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get real-time microphone levels with Phonegap/Cordova?

I am looking for a way to read volume data in real-time from the microphone. Just some kind of general "loudness". The purpose is to make lips move when you talk into the microphone on an html5 canvas element...

I basically want this plugin but for microphone levels instead of the camera:

https://github.com/casoninabox/luminance-cordova-ios

Does anyone know of any existing libraries to do this or how I might go about creating a plugin for iOS? I'm guessing it would involve the AVAudioSession?

like image 995
Jason Avatar asked Jan 20 '15 17:01

Jason


1 Answers

There is a plugin, that measures volume data in decibels: https://github.com/akofman/cordova-plugin-dbmeter

Install plugin with:

cordova plugin add cordova-plugin-dbmeter

Make sure that you add these lines to your app config.xml as that plugin doesn't currently support Swift 3.

<preference name="UseLegacySwiftLanguageVersion" value="true" />

Use plugin like that:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    DBMeter.start(function(dB){
        console.log(dB);
    });
}
like image 182
Nikita Kunevich Avatar answered Sep 20 '22 10:09

Nikita Kunevich