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.

Home Page:https://github.com/edimuj/app-audioinput-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error connecting to AudioNodes

Tattomoosa opened this issue · comments

I supplied an audio context to audioinput.start:
audioinput.start({ streamToWebAudio: true, audioContext: myContext });

but connecting audioinput like this doesn't work:
audioinput.connect(myContext.destination);
and this also doesn't work:
audioinput.connect(myGain);

it throws an error alert (i am using try/catch set up just like the demo) which says 'startCapture exception: Error: SyntaxError: DOM Exception 12'

but this way does work, at least it gets mic input coming out of the speakers:
audioinput.connect(audioinput.getAudioContext().destination)

I dug around in the source a bit and then checked if myContext == audioinput._audioContext and it doesn't. But it should, right?

Both myContext and audioinput._audioContext are valid audio contexts. I have some backup getUserMedia code for testing in browser, and the media stream source node it creates connects to exactly the same nodes in myContext and works just fine.

I am using Ionic, building with Ionic CLI (ionic build ios) then running on an iPhone 6 through XCode if that matters, but this seems like an issue somewhere in the javascript.

Found the problem!

A simple underscore in audioInputCapture.js, line 85:
audioinput._cfg._audioContext = cfg._audioContext || null;

This works as expected (in my app):
audioinput.start({ streamToWebAudio: true, _audioContext: myContext });

EDIT: Submitted a pull request with fix