void DisconnectAudioStream() { if (_microphoneStream != null) { // Destroy AudioPreprocessorPlaybackListener if (_audioPreprocessorPlaybackListener != null) { Destroy(_audioPreprocessorPlaybackListener); _audioPreprocessorPlaybackListener = null; } // Dispose of audio preprocessor if (_audioPreprocessor != null) { _audioPreprocessor.Dispose(); _audioPreprocessor = null; } // Close microphone stream _microphoneStream.Close(); // Dispose microphone device if (_oculusMicrophoneDevice != null) { _oculusMicrophoneDevice.Stop(); _oculusMicrophoneDevice.Dispose(); _oculusMicrophoneDevice = null; } if (_nativeMicrophoneDevice != null) { _nativeMicrophoneDevice.Stop(); _nativeMicrophoneDevice.Dispose(); _nativeMicrophoneDevice = null; } if (_unityMicrophoneDevice != null) { _unityMicrophoneDevice.Dispose(); _unityMicrophoneDevice = null; } // Clean up _unityMicrophoneDeviceDataReader = null; _microphoneStream = null; } // Remove audio output if (_audioOutput != null) { _audioOutput.Stop(); Destroy(_audioOutput); _audioOutput = null; } }