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

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

Open pgcan opened 5 years ago

pgcan commented 5 years ago

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

pgcan commented 5 years ago

An update here, if disabled TypedArrays then it works.

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

edimuj commented 5 years ago

Thanks @pgcan

I'll look into this as soon as possible.

taxilian commented 5 years ago

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.

pgcan commented 5 years ago

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.

aressler38 commented 4 years ago

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

edimuj commented 4 years ago

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

pgcan commented 4 years ago

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.

iexperto commented 4 years ago

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

taxilian commented 4 years ago

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.

taxilian commented 4 years ago

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)

sertal70 commented 4 years ago

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.

taxilian commented 4 years ago

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

Thanks for testing it =]

sertal70 commented 4 years ago

@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.