parent
72a10ad32b
commit
b7416c7c2b
2 changed files with 46 additions and 10 deletions
|
|
@ -822,7 +822,8 @@ async function buildAudioPipeline(rawStream) {
|
||||||
analyser.fftSize = 1024;
|
analyser.fftSize = 1024;
|
||||||
processedSource.connect(analyser);
|
processedSource.connect(analyser);
|
||||||
|
|
||||||
const timeData = new Float32Array(analyser.fftSize);
|
const supportsFloatTimeDomain = typeof analyser.getFloatTimeDomainData === 'function';
|
||||||
|
const timeData = supportsFloatTimeDomain ? new Float32Array(analyser.fftSize) : new Uint8Array(analyser.fftSize);
|
||||||
let localIsSpeaking = false;
|
let localIsSpeaking = false;
|
||||||
let speechFrames = 0;
|
let speechFrames = 0;
|
||||||
let silenceFrames = 0;
|
let silenceFrames = 0;
|
||||||
|
|
@ -832,12 +833,23 @@ async function buildAudioPipeline(rawStream) {
|
||||||
const checkVolume = () => {
|
const checkVolume = () => {
|
||||||
if (!state.voice.audioContext || state.voice.audioContext.state === 'closed') return;
|
if (!state.voice.audioContext || state.voice.audioContext.state === 'closed') return;
|
||||||
|
|
||||||
analyser.getFloatTimeDomainData(timeData);
|
try {
|
||||||
|
if (supportsFloatTimeDomain) {
|
||||||
|
analyser.getFloatTimeDomainData(timeData);
|
||||||
|
} else {
|
||||||
|
analyser.getByteTimeDomainData(timeData);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setTimeout(checkVolume, 60);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let sumSquares = 0;
|
let sumSquares = 0;
|
||||||
let peak = 0;
|
let peak = 0;
|
||||||
for (let i = 0; i < timeData.length; i++) {
|
for (let i = 0; i < timeData.length; i++) {
|
||||||
const v = timeData[i];
|
const v = supportsFloatTimeDomain
|
||||||
|
? timeData[i]
|
||||||
|
: (timeData[i] - 128) / 128;
|
||||||
sumSquares += v * v;
|
sumSquares += v * v;
|
||||||
const abs = Math.abs(v);
|
const abs = Math.abs(v);
|
||||||
if (abs > peak) peak = abs;
|
if (abs > peak) peak = abs;
|
||||||
|
|
@ -919,7 +931,13 @@ async function createLocalVoiceStream() {
|
||||||
video: false,
|
video: false,
|
||||||
};
|
};
|
||||||
const rawStream = await navigator.mediaDevices.getUserMedia(constraints);
|
const rawStream = await navigator.mediaDevices.getUserMedia(constraints);
|
||||||
const localStream = await buildAudioPipeline(rawStream);
|
let localStream = rawStream;
|
||||||
|
try {
|
||||||
|
localStream = await buildAudioPipeline(rawStream);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('voice audio pipeline failed, using raw mic stream', err);
|
||||||
|
state.voice.activeNoiseFilter = 'off';
|
||||||
|
}
|
||||||
state.voice.rawStream = rawStream;
|
state.voice.rawStream = rawStream;
|
||||||
state.voice.localStream = localStream;
|
state.voice.localStream = localStream;
|
||||||
if (state.voice.muted) {
|
if (state.voice.muted) {
|
||||||
|
|
@ -1067,7 +1085,7 @@ async function joinVoice() {
|
||||||
try {
|
try {
|
||||||
await createLocalVoiceStream();
|
await createLocalVoiceStream();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("microphone denied", err);
|
console.error('failed to initialize local voice stream', err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -785,7 +785,8 @@ async function buildAudioPipeline(rawStream) {
|
||||||
analyser.fftSize = 1024;
|
analyser.fftSize = 1024;
|
||||||
processedSource.connect(analyser);
|
processedSource.connect(analyser);
|
||||||
|
|
||||||
const timeData = new Float32Array(analyser.fftSize);
|
const supportsFloatTimeDomain = typeof analyser.getFloatTimeDomainData === 'function';
|
||||||
|
const timeData = supportsFloatTimeDomain ? new Float32Array(analyser.fftSize) : new Uint8Array(analyser.fftSize);
|
||||||
let localIsSpeaking = false;
|
let localIsSpeaking = false;
|
||||||
let speechFrames = 0;
|
let speechFrames = 0;
|
||||||
let silenceFrames = 0;
|
let silenceFrames = 0;
|
||||||
|
|
@ -795,12 +796,23 @@ async function buildAudioPipeline(rawStream) {
|
||||||
const checkVolume = () => {
|
const checkVolume = () => {
|
||||||
if (!state.voice.audioContext || state.voice.audioContext.state === 'closed') return;
|
if (!state.voice.audioContext || state.voice.audioContext.state === 'closed') return;
|
||||||
|
|
||||||
analyser.getFloatTimeDomainData(timeData);
|
try {
|
||||||
|
if (supportsFloatTimeDomain) {
|
||||||
|
analyser.getFloatTimeDomainData(timeData);
|
||||||
|
} else {
|
||||||
|
analyser.getByteTimeDomainData(timeData);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setTimeout(checkVolume, 60);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let sumSquares = 0;
|
let sumSquares = 0;
|
||||||
let peak = 0;
|
let peak = 0;
|
||||||
for (let i = 0; i < timeData.length; i++) {
|
for (let i = 0; i < timeData.length; i++) {
|
||||||
const v = timeData[i];
|
const v = supportsFloatTimeDomain
|
||||||
|
? timeData[i]
|
||||||
|
: (timeData[i] - 128) / 128;
|
||||||
sumSquares += v * v;
|
sumSquares += v * v;
|
||||||
const abs = Math.abs(v);
|
const abs = Math.abs(v);
|
||||||
if (abs > peak) peak = abs;
|
if (abs > peak) peak = abs;
|
||||||
|
|
@ -868,7 +880,13 @@ async function createLocalVoiceStream() {
|
||||||
video: false,
|
video: false,
|
||||||
};
|
};
|
||||||
const rawStream = await navigator.mediaDevices.getUserMedia(constraints);
|
const rawStream = await navigator.mediaDevices.getUserMedia(constraints);
|
||||||
const localStream = await buildAudioPipeline(rawStream);
|
let localStream = rawStream;
|
||||||
|
try {
|
||||||
|
localStream = await buildAudioPipeline(rawStream);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('voice audio pipeline failed, using raw mic stream', err);
|
||||||
|
state.voice.activeNoiseFilter = 'off';
|
||||||
|
}
|
||||||
state.voice.rawStream = rawStream;
|
state.voice.rawStream = rawStream;
|
||||||
state.voice.localStream = localStream;
|
state.voice.localStream = localStream;
|
||||||
if (state.voice.muted) {
|
if (state.voice.muted) {
|
||||||
|
|
@ -1016,7 +1034,7 @@ async function joinVoice() {
|
||||||
try {
|
try {
|
||||||
await createLocalVoiceStream();
|
await createLocalVoiceStream();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("microphone denied", err);
|
console.error('failed to initialize local voice stream', err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue