[mirotalk] - refactor noise supression
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user