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

Is it possible to extract raw signal every two seconds using events? #86

Closed DanielTizon closed 5 years ago

DanielTizon commented 5 years ago

Hi, I would like to know if it is possible to get raw signal every two seconds. I am a bit confusing about how is it related with bufferSize option, and how I could to get a raw signal that represents two seconds of audio.

edimuj commented 5 years ago

The samplerate is the number of samples captured per second, so calculating the length in seconds of a mono (1 channel) buffer can be done like this: var bufferLengthInSeconds = 1 / (sampleRate / bufferSize);

DanielTizon commented 5 years ago

Thanks @edimuj

So if I am using a sampleRate=audioinput.SAMPLERATE.CD_AUDIO_44100Hz, and I use bufferSize=44100, then events with raw audio will be fired every second?

edimuj commented 5 years ago

Yes, theoretically but the actual buffersize of each buffer can sadly vary during execution and it is not possible to set it to whatever you want depending on the device the app executes on (I've have had some problems above 16384 on some devices), so I would rather queue up buffers and then consume them until you get 44100 samples for one second or 88200 for two seconds etc.

edimuj commented 5 years ago

Since there haven't been any activity for a while, I'm closing down this issue.