[mirotalk] - refactor noise supression

This commit is contained in:
Miroslav Pejic
2025-12-17 16:34:42 +01:00
parent 2618d0879e
commit fe6342f6f4
8 changed files with 111 additions and 33 deletions
+24 -1
View File
@@ -129,10 +129,18 @@ class RNNoiseProcessor {
try {
this.uiManager.updateStatus('🎤 Starting audio processing...', 'info');
this.audioContext = new AudioContext();
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
const sampleRate = this.audioContext.sampleRate;
this.uiManager.updateStatus(`🎵 Audio context created with sample rate: ${sampleRate}Hz`, 'info');
if (this.audioContext.state === 'suspended') {
try {
await this.audioContext.resume();
} catch (e) {
// ignore
}
}
this.mediaStream = mediaStream;
if (!this.mediaStream.getAudioTracks().length) {
throw new Error('No audio tracks found in the provided media stream');
@@ -162,10 +170,25 @@ class RNNoiseProcessor {
return this.destinationNode.stream;
} catch (error) {
this.uiManager.updateStatus('❌ Error: ' + error.message, 'error');
console.error('RNNoise startProcessing error:', error);
this.stopProcessing();
return null;
}
}
stopProcessing() {
this.mediaStream = null;
try {
this.sourceNode?.disconnect();
} catch (e) {}
try {
this.workletNode?.disconnect();
} catch (e) {}
try {
this.destinationNode?.stream?.getTracks?.().forEach((t) => t.stop());
} catch (e) {}
if (this.audioContext && this.audioContext.state !== 'closed') {
this.audioContext.close();
this.audioContext = null;