Esempio n. 1
0
        /// <summary>
        /// 监控 录音 打开
        /// </summary>
        /// <param name="recordingDevice"></param>
        public void BeginMonitoring(int recordingDevice = 0)
        {
            if (recordingState != RecordingState.Stopped)
            {
                throw new InvalidOperationException("Can't begin monitoring while we are in this state: " +
                                                    recordingState.ToString());
            }

            waveIn = new WaveIn();
            //waveIn.DeviceNumber = recordingDevice;
            waveIn.DataAvailable    += OnDataAvailable;
            waveIn.RecordingStopped += OnRecordingStopped;
            waveIn.WaveFormat        = recordingFormat;
            waveIn.StartRecording();
            //TryGetVolumeControl();
            recordingState = RecordingState.Monitoring;
        }
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        public virtual void BeginRecording(string waveFileName, bool appendToFile)
        {
            if (_recordingState == RecordingState.NotYetStarted)
            {
                BeginMonitoring();
            }

            if (_recordingState != RecordingState.Monitoring)
            {
                throw new InvalidOperationException("Can't begin recording while we are in this state: " + _recordingState.ToString());
            }

            lock (this)
            {
                if (_waveInBuffersChanged)
                {
                    CloseWaveIn();
                    BeginMonitoring();
                }

                _bytesRecorded = 0;

                WaveFileWriter writer;
                if (!File.Exists(waveFileName) || !appendToFile)
                {
                    writer = new WaveFileWriter(waveFileName, _recordingFormat);
                }
                else
                {
                    var buffer = GetAudioBufferToAppendTo(waveFileName);
                    writer = new WaveFileWriter(waveFileName, _recordingFormat);
                    writer.Write(buffer, 0, buffer.Length);
                }
                _fileWriterThread = new FileWriterThread(writer);

                _recordingStartTime = DateTime.Now;
                _prevRecordedTime   = 0d;
                RecordingState      = RecordingState.Recording;
            }
            if (RecordingStarted != null)
            {
                RecordingStarted(this, EventArgs.Empty);
            }
        }
 public void BeginRecording(string waveFileName)
 {
     if (recordingState != RecordingState.Monitoring)
     {
         throw new InvalidOperationException("Can't begin recording while we are in this state: " + recordingState.ToString());
     }
     writer         = new WaveFileWriter(waveFileName, recordingFormat);
     recordingState = RecordingState.Recording;
 }
Esempio n. 4
0
        public void BeginMonitoring(int recordingDevice)
        {
            if (recordingState != RecordingState.Stopped)
            {
                throw new InvalidOperationException("Can't begin monitoring while we are in this state: " + recordingState.ToString());
            }

            waveIn = new WaveInEvent();
            waveIn.DeviceNumber      = recordingDevice;
            waveIn.DataAvailable    += OnDataAvailable;
            waveIn.RecordingStopped += OnRecordingStopped;
            waveIn.WaveFormat        = recordingFormat;
            //wi.WaveFormat = new NAudio.Wave.WaveFormat(RATE, 1);
            //waveIn.BufferMilliseconds = BUFFERSIZE; //(int)((double)BUFFERSIZE / (double)RATE * 1000.0);
            waveIn.BufferMilliseconds = (int)((double)BUFFERSIZE / (double)RATE * 1000.0);
            //waveIn.BufferMilliseconds = 5120;

            bwp = new BufferedWaveProvider(waveIn.WaveFormat);
            bwp.BufferLength            = BUFFERSIZE * 2;
            bwp.DiscardOnBufferOverflow = true;

            waveIn.StartRecording();
            _audioEvaluator.Start(new WaveInEvent()
            {
                DeviceNumber = recordingDevice
            });
            //_audioEvaluator.Start(waveIn);

            recordingState = RecordingState.Monitoring;
        }
        public void BeginRecording()
        {
            if (recordingState != RecordingState.Stopped)
            {
                throw new InvalidOperationException("Can't begin monitoring while we are in this state: " + recordingState.ToString());
            }

            base.StartRecording();
            recordingState = RecordingState.Recording;
        }