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

No Sound or periodic 'click-click' sound when using web audio option.

pgcan opened this issue · comments

commented

Hi,
Looking at the plugin code and documentation it looks pretty obvious that capturing WebAudio is minutes of task using this plugin but I have been struggling for last 2 days to get this working.

I installed the Demo App and tested "WebAudio" demo but all I hear is a 'click-click' sound every half second. There is no error and all looks pretty working.

I have tested on Android 9.0 and Android 6.0 but same behavior. Not sure what is broken or missed by me.

Is someone else also got the same issue? Please help.

Other details:
Cordova 8.0
Android: 9.0 and 6.0

commented

An update here,
if disabled TypedArrays then it works.

var hasTypedArrays = false;// 'Int16Array' in window && 'Float32Array' in window;

commented

Thanks @pgcan

I'll look into this as soon as possible.

That is strange; I actually was having some trouble on android which might be related to this, but ended up just using getUserMedia on android so I didn't worry about it. It was definitely working on iOS.

I can try to look at this a bit later; it could be there is an issue with the way we're initializing the typedarrays or the data isn't getting copied correctly on android.

commented

Another major issue that I found with plugin's WebAudio logic, is that the scheduling of BufferSource is done based on "setTimeOut" in method "_getNextToPlay" however AudioContext has its own timer which is more precise (double) and must be used.

I will create pull request to fix this.

BaseAudioContext

BaseAudioContext.currentTime (Read only)
Returns a double representing an ever-increasing hardware time in seconds used for scheduling. It starts at 0.

I just started using this plugin and ran into this same issue. Setting var hasTypedArrays = false; as @pgcan says temporarily fixes the problem.

commented

@pgcan Have you been able to look into this any more?

commented

We do not use this plugin in our app anymore. So I couldn't get time to look into it. However, if possible then someone can look into changes in method "_playAudio" my repo commit to understand AudioContext scheduling. But I am still hopeful to get time soon.

Same problem, var hasTypedArrays = false; fixes the issue. Is any plan to fix this?
In my opinion this should be a setting instead of an "auto-detection"
This change also break the demo in some devices.
https://github.com/edimuj/app-audioinput-demo

I wrote the original PR to use typedarrays and it seemed to be working, but I ended up switching to use getUserMedia on android so didn't see the issue; unfortunately that makes it harder for me to troubleshoot it.

I'm off my day job for the next week so I'm going to see if I can figure this out, but if anyone currently affected by the issue is available to assist a bit that would be a big help -- email me at taxilian at gmail and we'll work out a more effective / faster communications method.

okay; I have looked over the code and could only come up with one slightly shot-in-the-dark theory as to what is going on. Would someone please try https://github.com/HamStudy/cordova-plugin-audioinput/tree/try_fix_android and see if it resolves the issue? (I can't repro)

Hi @taxilian, I tried your fix but it doesn't solve the issue: the recording output contains a periodic "click" only, there is no sound at all. The only way to have it work is to set hasTypedArrays to false: doing so I have sound in the recording output, although the periodic "click" is still present.

Really really strange; I have no idea why typed arrays would not work on android, but it ... really sucks.

Thanks for testing it =]

@taxilian you're welcome. I suspect the root cause is not typed arrays implementation itself, because everything is fine if I record using event instead of web audio.