mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-08-28 10:04:12 +00:00
feat(audio): fix Codec2MicrophoneRecorder with silent tap for audio processing and ensure audio context resumes correctly
This commit is contained in:
+21
@@ -33,6 +33,18 @@ class Codec2MicrophoneRecorder {
|
||||
// send mic audio to audio worklet
|
||||
this.mediaStreamSource = this.audioContext.createMediaStreamSource(this.microphoneMediaStream);
|
||||
this.mediaStreamSource.connect(this.audioWorkletNode);
|
||||
this._silentTap = this.audioContext.createGain();
|
||||
this._silentTap.gain.value = 0;
|
||||
this.audioWorkletNode.connect(this._silentTap);
|
||||
this._silentTap.connect(this.audioContext.destination);
|
||||
|
||||
if (typeof this.audioContext.resume === "function") {
|
||||
try {
|
||||
await this.audioContext.resume();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// successfully started recording
|
||||
return true;
|
||||
@@ -58,6 +70,15 @@ class Codec2MicrophoneRecorder {
|
||||
this.audioWorkletNode.disconnect();
|
||||
}
|
||||
|
||||
if (this._silentTap) {
|
||||
try {
|
||||
this._silentTap.disconnect();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
this._silentTap = null;
|
||||
}
|
||||
|
||||
// close audio context
|
||||
if (this.audioContext && this.audioContext.state !== "closed") {
|
||||
this.audioContext.close();
|
||||
|
||||
Reference in New Issue
Block a user