mirror of
https://github.com/open-webui/open-webui
synced 2024-11-06 08:56:39 +00:00
fix: silence monitoring
This commit is contained in:
parent
4a73a01c24
commit
7eaf83cb7d
@ -80,12 +80,17 @@
|
|||||||
audioStreamSource.connect(analyser);
|
audioStreamSource.connect(analyser);
|
||||||
|
|
||||||
const bufferLength = analyser.frequencyBinCount;
|
const bufferLength = analyser.frequencyBinCount;
|
||||||
|
|
||||||
|
const domainData = new Uint8Array(bufferLength);
|
||||||
const timeDomainData = new Uint8Array(analyser.fftSize);
|
const timeDomainData = new Uint8Array(analyser.fftSize);
|
||||||
|
|
||||||
|
let lastSoundTime = Date.now();
|
||||||
|
|
||||||
const detectSound = () => {
|
const detectSound = () => {
|
||||||
const processFrame = () => {
|
const processFrame = () => {
|
||||||
if (recording && !loading) {
|
if (recording && !loading) {
|
||||||
analyser.getByteTimeDomainData(timeDomainData);
|
analyser.getByteTimeDomainData(timeDomainData);
|
||||||
|
analyser.getByteFrequencyData(domainData);
|
||||||
|
|
||||||
// Calculate RMS level from time domain data
|
// Calculate RMS level from time domain data
|
||||||
const rmsLevel = calculateRMS(timeDomainData);
|
const rmsLevel = calculateRMS(timeDomainData);
|
||||||
@ -98,6 +103,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
visualizerData = visualizerData;
|
visualizerData = visualizerData;
|
||||||
|
|
||||||
|
if (domainData.some((value) => value > 0)) {
|
||||||
|
lastSoundTime = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recording && Date.now() - lastSoundTime > 3000) {
|
||||||
|
if ($settings?.speechAutoSend ?? false) {
|
||||||
|
confirmRecording();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.requestAnimationFrame(processFrame);
|
window.requestAnimationFrame(processFrame);
|
||||||
@ -203,6 +218,7 @@
|
|||||||
rounded-full"
|
rounded-full"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
dispatch('cancel');
|
dispatch('cancel');
|
||||||
|
stopRecording();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
|
Loading…
Reference in New Issue
Block a user