示例#1
0
        void StartRecording()
        {
            try
            {
                if (!_isRecording)
                {
                    _source = new CaptureSource();
                    if ((CaptureDeviceConfiguration.AllowedDeviceAccess | CaptureDeviceConfiguration.RequestDeviceAccess()) & (_source.State == CaptureState.Stopped))
                    {

                        _sink = new MemoryAudioSink();

                        AudioFormat desiredAudioFormat = null;
                        foreach (AudioFormat audioFormat in _source.AudioCaptureDevice.SupportedFormats)
                        {
                            if (audioFormat.SamplesPerSecond == 8000 && audioFormat.BitsPerSample == 16 && audioFormat.Channels == 1 && audioFormat.WaveFormat == WaveFormatType.Pcm)
                            {
                                desiredAudioFormat = audioFormat;
                            }
                        }

                        if (desiredAudioFormat == null)
                        {
                            ShowMessageBox("Your sound device may not found or in use also please make sure that it's support (16 bits,8000 samples,1 channel) please tell your system administrator about this problem!");
                            return;
                        }

                        _sink.OnBufferFulfill += new EventHandler(SendVoiceBuffer);
                        _source.AudioCaptureDevice.DesiredFormat = desiredAudioFormat;
                        _sink.CaptureSource = _source;
                        _source.Start();
                        _isRecording = true;
                    }

                }
            }
            catch (Exception ex)
            {
                ShowMessageBox("Your sound device may in use! " + ex.Message);
            }
        }
示例#2
0
 void StartRecording()
 {
     _sink = new MemoryAudioSink();
     _sink.OnBufferFulfill += new EventHandler(SendVoiceBuffer);
     _sink.CaptureSource = _source;
     _isRecording = true;
 }