public IAsyncOperation <AudioFrameReader> OpenAudioFrameReaderAsync() { return(Task.Run(async() => { if (AudioReader == null) { var microphones = await DeviceInformation.FindAllAsync(DeviceInformation.GetAqsFilterFromDeviceClass(DeviceClass.AudioCapture)); var kinectMicArray = microphones.FirstOrDefault(mic => mic.Name.ToLowerInvariant().Contains("xbox nui sensor")); if (kinectMicArray != null) { //TODO: review parameters var settings = new AudioGraphSettings(AudioRenderCategory.Speech); settings.EncodingProperties = AudioEncodingProperties.CreatePcm(16000, 4, 32); settings.EncodingProperties.Subtype = MediaEncodingSubtypes.Float; settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.LowestLatency; settings.DesiredRenderDeviceAudioProcessing = Windows.Media.AudioProcessing.Raw; var audioGraphResult = await AudioGraph.CreateAsync(settings); if (audioGraphResult.Status == AudioGraphCreationStatus.Success) { var inputNodeResult = await audioGraphResult.Graph.CreateDeviceInputNodeAsync(MediaCategory.Speech, audioGraphResult.Graph.EncodingProperties, kinectMicArray); if (inputNodeResult.Status == AudioDeviceNodeCreationStatus.Success) { var output = audioGraphResult.Graph.CreateFrameOutputNode(audioGraphResult.Graph.EncodingProperties); AudioReader = new AudioFrameReader(audioGraphResult.Graph, output); } } } } AudioReader?.Open(); return AudioReader; }).AsAsyncOperation()); }
public IAsyncAction CloseAsync() { return(Task.Run(async() => { await _bodyIndexReader?.CloseAsync(); _bodyIndexReader?.Dispose(); _bodyIndexReader = null; await _bodyReader?.CloseAsync(); _bodyReader?.Dispose(); _bodyReader = null; await _colorReader?.CloseAsync(); _colorReader?.Dispose(); _colorReader = null; await _depthReader?.CloseAsync(); _depthReader?.Dispose(); _depthReader = null; _audioReader?.Close(); _audioReader?.Dispose(); _audioReader = null; if (Type != SensorType.NetworkClient) { _mediaCapture?.Dispose(); _mediaCapture = null; } else { _sensorConnection.Dispose(); _sensorConnection = null; } }).AsAsyncAction()); }