[mirotalksfu] - improve getMicrophoneVolumeIndicator
هذا الالتزام موجود في:
@@ -401,22 +401,24 @@ function addChild(device, els) {
|
|||||||
// ####################################################
|
// ####################################################
|
||||||
|
|
||||||
function getMicrophoneVolumeIndicator(stream) {
|
function getMicrophoneVolumeIndicator(stream) {
|
||||||
stopMicrophoneProcessing();
|
if (isAudioContextSupported() && hasAudioTrack(stream)) {
|
||||||
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
stopMicrophoneProcessing();
|
||||||
const microphone = audioContext.createMediaStreamSource(stream);
|
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
scriptProcessor = audioContext.createScriptProcessor(1024, 1, 1);
|
const microphone = audioContext.createMediaStreamSource(stream);
|
||||||
scriptProcessor.onaudioprocess = function (event) {
|
scriptProcessor = audioContext.createScriptProcessor(1024, 1, 1);
|
||||||
const inputBuffer = event.inputBuffer.getChannelData(0);
|
scriptProcessor.onaudioprocess = function (event) {
|
||||||
let sum = 0;
|
const inputBuffer = event.inputBuffer.getChannelData(0);
|
||||||
for (let i = 0; i < inputBuffer.length; i++) {
|
let sum = 0;
|
||||||
sum += inputBuffer[i] * inputBuffer[i];
|
for (let i = 0; i < inputBuffer.length; i++) {
|
||||||
}
|
sum += inputBuffer[i] * inputBuffer[i];
|
||||||
const rms = Math.sqrt(sum / inputBuffer.length);
|
}
|
||||||
const volume = Math.max(0, Math.min(1, rms * 10));
|
const rms = Math.sqrt(sum / inputBuffer.length);
|
||||||
updateVolumeIndicator(volume);
|
const volume = Math.max(0, Math.min(1, rms * 10));
|
||||||
};
|
updateVolumeIndicator(volume);
|
||||||
microphone.connect(scriptProcessor);
|
};
|
||||||
scriptProcessor.connect(audioContext.destination);
|
microphone.connect(scriptProcessor);
|
||||||
|
scriptProcessor.connect(audioContext.destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopMicrophoneProcessing() {
|
function stopMicrophoneProcessing() {
|
||||||
@@ -436,6 +438,20 @@ function updateVolumeIndicator(volume) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAudioContextSupported() {
|
||||||
|
return !!(window.AudioContext || window.webkitAudioContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasAudioTrack(mediaStream) {
|
||||||
|
const audioTracks = mediaStream.getAudioTracks();
|
||||||
|
return audioTracks.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasVideoTrack(mediaStream) {
|
||||||
|
const videoTracks = mediaStream.getVideoTracks();
|
||||||
|
return videoTracks.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
// API CHECK
|
// API CHECK
|
||||||
// ####################################################
|
// ####################################################
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم