Reputation: 548
I need to capture some input from microphone in javascript (from a browser) and playback audio in real time. But the latency I get is really ugly (about 200ms).
How can I reduce this ? Is javascript a good option to expect latency like 20 ms ?
I simply tried to capture the audio using getUserMedia()
and AudioContext
utils from Web Audio API
and play it :
const constraints = {
video: false,
audio: {
echoCancellation: false,
noiseSuppression: false,
autoGainControl: false
}
}
var context = new AudioContext({
latencyHint: 'interactive',
sampleRate: 44100,
});
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
var source = context.createMediaStreamSource(stream);
source.connect(context.destination);
});
Any suggestion is welcome to minimize latency. Thanks
Upvotes: 1
Views: 1766
Reputation: 6056
Don't know if this will help, but you should definitely turn off echo cancellation and other input processing if you're sending the audio to WebAudio. See echoCancellation constraint for details. You probably also want to turn off gain control and noise suppression.
Upvotes: 1