edimuj / cordova-plugin-audioinput

This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.
https://github.com/edimuj/app-audioinput-demo
MIT License
161 stars 88 forks source link

need a way to receive a notification when audio stops recording #43

Closed mreinstein closed 7 years ago

mreinstein commented 7 years ago

Looking at this line: https://github.com/edimuj/cordova-plugin-audioinput/blob/master/www/audioInputCapture.js#L136

exec(null, audioinput._audioInputErrorEvent, "AudioInputCapture", "stop", []);

The first parameter is the success callback according to https://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/#the-javascript-interface

I'm wondering if there's a way we can fire an event when the microphone stops. I'm having an issue with my application where I call audioinput.stop(), and then I immediately play some web audio. The audio starts playing with reduced volume. Eventually the microphone stops, and then the playing audio goes to full volume. Having a way to know when the microphone is no longer acquiring data enables me to wait before playing the audio

mreinstein commented 7 years ago

@edimuj I've tried locally modifying the plugin to get a success callback to fire, but I wasn't having much luck. Here are the changes I tried:

In audioInputCapture.js

audioinput.stop = function () {
    if (audioinput._capturing) {
        audioinput._capturing = false;
        exec(audioinput._audioInputStopEvent, audioinput._audioInputErrorEvent, "AudioInputCapture", "stop", [ ]);
    }

    if (audioinput._cfg.streamToWebAudio) {
        if (audioinput._timerGetNextAudio) {
            clearTimeout(audioinput._timerGetNextAudio);
        }
        audioinput._audioDataQueue = null;
    }
};

audioinput._audioInputStopEvent = function (e) {
    cordova.fireWindowEvent("audioinputerror", { message: 'noerror' });
};

Maybe I'm missing changes in the native side to get the success callback to fire? I'm unsure. Any thoughts/feedback would be welcome. Happy to submit a PR if we can get this working.

edimuj commented 7 years ago

@mreinstein thanks. I'll start looking into this next week. I agree, there is probably some stuff needed on the native side to get the callback working, both on iOS and Android.

edimuj commented 7 years ago

@mreinstein sorry for the long delay, I have been extremely busy with commercial projects since summer. If you submit a PR, I’ll be happy to merge it.

mreinstein commented 7 years ago

@edimuj no worries, I've actually moved away from native to web development for this application. As of ios11, safari supports microphone input! :)