Enable auto gain control, echo cancellation and noise suppression

This commit is contained in:
Trevor Slocum 2019-12-02 17:45:54 -08:00
parent c54b7c799e
commit 5739b433ec
1 changed files with 45 additions and 38 deletions

View File

@ -9,6 +9,14 @@ var ptt = false;
var printStats = false;
var pc;
var RTCConstraints = {
audio: {
autoGainControl: true,
echoCancellation: true,
noiseSuppression: true,
},
video: false
};
var RTCOfferOptions = {
offerToReceiveAudio: 1,
offerToReceiveVideo: 0,
@ -75,48 +83,47 @@ $(document).ready(function () {
}
};
navigator.mediaDevices.getUserMedia({audio: true, video: false})
.then(localStream => {
audioTracks = localStream.getAudioTracks();
if (audioTracks.length > 0) {
console.log(`Using Audio device: ${audioTracks[0].label} - tracks available: ${audioTracks}`);
navigator.mediaDevices.getUserMedia(RTCConstraints).then(localStream => {
audioTracks = localStream.getAudioTracks();
if (audioTracks.length > 0) {
console.log(`Using Audio device: ${audioTracks[0].label} - tracks available: ${audioTracks}`);
}
audioTrack = audioTracks[0];
pc.addTrack(audioTrack);
pc.getSenders()[0].replaceTrack(null);
pc.ontrack = function (event) {
console.log(`onTrack ${event.streams.length}`);
pc.addTransceiver(event.streams[0].getAudioTracks()[0], {'direction': 'sendrecv'});
var el = document.getElementById('audioplayer');
el.autoplay = true;
el.srcObject = event.streams[0];
voice = true;
if (!shownPTTHelp) {
shownPTTHelp = true;
Log("* Note: Push-to-talk is bound to <F8>");
}
audioTrack = audioTracks[0];
$('#voicepttcontainer').css('display', 'table-row');
$('#voiceinactiveleft').css('display', 'none');
$('#voiceactiveleft').css('display', 'inline-block');
$('#voiceinactiveright').css('display', 'none');
$('#voiceactiveright').css('display', 'inline-block');
$('#voiceButton').html('Quit voice chat');
pc.addTrack(audioTrack);
pc.getSenders()[0].replaceTrack(null);
updateVoiceStatus();
};
pc.ontrack = function (event) {
console.log(`onTrack ${event.streams.length}`);
pc.addTransceiver(event.streams[0].getAudioTracks()[0], {'direction': 'sendrecv'});
var el = document.getElementById('audioplayer');
el.autoplay = true;
el.srcObject = event.streams[0];
voice = true;
if (!shownPTTHelp) {
shownPTTHelp = true;
Log("* Note: Push-to-talk is bound to <F8>");
}
$('#voicepttcontainer').css('display', 'table-row');
$('#voiceinactiveleft').css('display', 'none');
$('#voiceactiveleft').css('display', 'inline-block');
$('#voiceinactiveright').css('display', 'none');
$('#voiceactiveright').css('display', 'inline-block');
$('#voiceButton').html('Quit voice chat');
updateVoiceStatus();
};
pc.createOffer(RTCOfferOptions)
.then(onRTCDescription, onRTCDescriptionError);
}).catch(Log);
pc.createOffer(RTCOfferOptions)
.then(onRTCDescription, onRTCDescriptionError);
}).catch(Log);
});
$("#voiceptt").on("touchstart", function (e) {