private void OnDestroy() { if (micStream == null) { return; } // Stop the microphone stream. WindowsMicrophoneStreamErrorCode result = micStream.StopStream(); if (result != WindowsMicrophoneStreamErrorCode.Success) { Debug.Log($"Failed to stop the microphone stream. {result}"); } // Uninitialize the microphone stream. micStream.Uninitialize(); micStream = null; // Restore the initial material settings. if (visibleMaterial != null) { visibleMaterial.SetColor("_WireColor", defaultMaterialColor); visibleMaterial.SetInt("_WireThickness", defaultWireThickness); } }
private void Awake() { // We do not wish to play the ambient room sound from the audio source. gameObject.GetComponent <AudioSource>().volume = 0.0f; spatialMeshObserver = (CoreServices.SpatialAwarenessSystem as IMixedRealityDataProviderAccess)?.GetDataProvider <IMixedRealitySpatialAwarenessMeshObserver>(); visibleMaterial = spatialMeshObserver?.VisibleMaterial; if (visibleMaterial != null) { // Cache the initial material settings. defaultMaterialColor = visibleMaterial.GetColor("_WireColor"); defaultWireThickness = visibleMaterial.GetInt("_WireThickness"); visibleMaterial.SetColor("_WireColor", meshColor); } micStream = new WindowsMicrophoneStream(); if (micStream == null) { Debug.Log("Failed to create the Windows Microphone Stream object"); } micStream.Gain = inputGain; // Initialize the microphone stream. WindowsMicrophoneStreamErrorCode result = micStream.Initialize(WindowsMicrophoneStreamType.HighQualityVoice); if (result != WindowsMicrophoneStreamErrorCode.Success) { Debug.Log($"Failed to initialize the microphone stream. {result}"); return; } // Start the microphone stream. // Do not keep the data and do not preview. result = micStream.StartStream(false, false); if (result != WindowsMicrophoneStreamErrorCode.Success) { Debug.Log($"Failed to start the microphone stream. {result}"); } }