I want to make a Javascript program to process some audio from microphone. But when I make just a basic example, like get audio from microphone and play it back without any processing, just like this
source = audioCtx.createMediaStreamSource(stream);
source.connect(audioCtx.destination);
I get 200 milliseconds latency between input and output audio. I tried in Google Chrome and Firefox on 2 different PCs with Windows 7 and Windows 10 and it looks the same everywhere. I got this number (200ms) by recording and analysing audio with an external device, not just by my ears.
In official W3C specification here they tell about 3-50 ms latency. 30-50 ms is what I need. I do not really need 3-5 ms.
I tried to play with latency parameter like this
navigator.mediaDevices.getUserMedia({
audio: {
latency: 0.05,
echoCancellation: false,
mozNoiseSuppression: true,
mozAutoGainControl: false
}
});
but looks like it is ignored by Chrome and FireFox.
My full example is available here.
https://jsfiddle.net/xfq3ykp7/71/
Is it browser/hardware limitation or I am doing something wrong? Can anyone hear some latency with my example? Usually, it is easy to check it with hitting a table near a microphone. for 200 ms there is a noticeable delay between the hit and its sound.
I do not need complicated things like scheduled audio events etc which are needed for games or online musical instruments. I just need to decrease latency in my simple example from 200 ms to 50 ms or ideally to 20 ms.
UPDATE1:
I could make 70 ms on Windows 10 and 100 ms on Windows 7 in Firefox with that code change
var p = navigator.mediaDevices.getUserMedia({
audio: {
latency: 0.02,
echoCancellation: false,
mozNoiseSuppression: false,
mozAutoGainControl: false
}
});
Thanks to firefox support (https://bugzilla.mozilla.org/show_bug.cgi?id=1375466). But they tell that 30 ms should be possible. The question is still open "How to get 30 ms latency on Windows?" and "What is hardware requirements?".