question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Window event 'audioinput' not being triggered in Ionic 3

See original GitHub issue

Hi Guys, i’m very happy i found your plugin, i’ve been looking for a plugin with similar API to the web audio API for a long time, but i can’t make the audioinput event get triggered

I’m emulating IOS/Android in the browser

The plugin was installed correctly. I used this line on top of my Angular provider to make audioinput work

declare let audioinput: any;

My initialize function: the callback contains permission stuff and a method that calls audioinput.start() all permissions work perfectly

let captureCfg = {
      sampleRate: 16000,
      bufferSize: PROCESSING_BUFFER_LENGTH,
      channels: 1,
      format: audioinput.FORMAT.PCM_16BIT,
      audioSourceType: audioinput.AUDIOSOURCE_TYPE.DEFAULT,
      audioContext: this.audioContext
};
 audioinput.initialize(captureCfg, () => {...})

But when i call my start function , i’m using streamToWebAudio: true because i want to receive the data while recording in order to process, the event is never triggered.

audioinput.start({streamToWebAudio : true});
window.addEventListener('audioinput', (event) => {
    // THIS EVENT NEVER GETS TRIGGERED
     this.onAudioProcess(event);
}, false);
audioinput.connect(audioinput.getAudioContext().destination);

I did some debugging inside the plugin and the exec() function gets called with all the right properties but audioinput._audioInputEvent() never gets called, EVER.

What am i doing wrong? help me

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gabrielfreirecommented, Dec 10, 2018

Also make sure you have this on your package.json

"cordova": {
    "plugins": {
      "cordova-plugin-audioinput": {}
    }
}
1reaction
gabrielfreirecommented, Dec 10, 2018

Hi @Bobisback , after installing it you need to ensure it was added on config.xml if not, add this line <plugin name="cordova-plugin-audioinput" spec="^1.0.1" /> change the spec value to your version in typescript you need to declare global variables on the top of your files, like audioinput

declare let audioinput: any;

and then just make it listen for the event

window.addEventListener('audioinput', (event) => {
      /* processing event.data */;
}, false);

this is where i ask for the mic to record

                let captureCfg = {
                        sampleRate: 16000,
                        bufferSize: PROCESSING_BUFFER_LENGTH,
                        channels: 1,
                        format: audioinput.FORMAT.PCM_16BIT,
                        audioSourceType: audioinput.AUDIOSOURCE_TYPE.DEFAULT
                    };
                    audioinput.initialize(captureCfg, () => {
                        audioinput.checkMicrophonePermission((hasPermission) => {
                            if(hasPermission){
                                console.warn('Already have permission to record');
                                // startRecording
                                this.connectNodes();
                            } else {
                                console.warn('No permission to record yet');
                                console.warn('Asking...');
                                audioinput.getMicrophonePermission((hasPermission, message) => {
                                    if(hasPermission) {
                                        console.warn('User granted permission to record');
                                        this.connectNodes();
                                    } else {
                                        console.warn('User denied permission to record');
                                        this.status = RecordStatus.GETUSERMEDIA_ERROR;
                                    }
                                });
                            }
                        });
                    });

this is where i connect the nodes

audioinput.start({ bufferSize: PROCESSING_BUFFER_LENGTH, streamToWebAudio: false });
audioinput.connect(this.audioContext.destination);

p.s. above are my options, go to the docs to see what they mean

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic3 Events not working - Stack Overflow
In your code console.log('before unauthorised'); //This line works when a 401 occurs works because app.component.ts is a file that gets called ...
Read more >
@frat/cordova-plugin-audioinput - npm
When using the event based approach, the plugin emits the following window events: audioinput; audioinputerror. Basic Usage Example - AudioNode.
Read more >
Media Capture and Streams - W3C
This document defines a set of JavaScript APIs that allow local media, including audio and video, to be requested from a platform.
Read more >
The 9 Most Common Mistakes That Ionic Developers Make
Common Mistake #1: Forgetting to Enable Native Scrolling​​ Native Scrolling allows Ionic to listen to scrolling events on supported webviews. It makes Pull...
Read more >
Releases - Docs - OpenVidu
Now the event is always triggered for new users if the session is being ... Before this property, an OpenVidu cluster did not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found