private void StartWasapi()
        {
            var deviceInfos = GetAudioDeviceInfos();

            if (deviceInfos.Count == 0)
            {
                throw new Exception("No audio devices found.");
            }

            DeviceInformation deviceInfo;

            if (DesiredDeviceNumber.HasValue && DesiredDeviceNumber.Value < deviceInfos.Count)
            {
                deviceInfo = deviceInfos[DesiredDeviceNumber.Value];
            }
            else
            {
                deviceInfo = deviceInfos[0];
            }

            Label = deviceInfo.Name;

            WasapiIn = new WasapiCaptureRT(deviceInfo.Id);
            WasapiIn.DataAvailable += new EventHandler <WaveInEventArgs>(WasapiIn_DataAvailable);
            WasapiIn.StartRecording();
        }
Example #2
0
        private void StartRecording()
        {
            var recorder = new WasapiCaptureRT();

            //recorder.WaveFormat = new WaveFormat(44100, 16, 2);
            //var devices = await DeviceInformation.FindAllAsync();
            //foreach (var device in devices)
            //{
            //    Debug.WriteLine(device.Name + "  " + device.Id);
            //}
            //recorder.WaveFormat = new WaveFormat();
            //recorder.WaveFormat = new WaveFormat(8000, 16, 1);
            recorder.WaveFormat     = new WaveFormat(48000, 16, 1);
            recorder.DataAvailable += OnDataAvailable;
            Debug.WriteLine("Wave format: " + recorder.WaveFormat);
            Debug.WriteLine(WasapiCaptureRT.GetDefaultCaptureDevice());
            recorder.StartRecording();
        }