Exemple #1
0
        public void Start()
        {
            _Writer.Width      = _CaptureRegion.Width;
            _Writer.Height     = _CaptureRegion.Height;
            _Writer.FrameRate  = _FrameRate;
            _Writer.BitRate    = _BitRate;
            _Writer.VideoCodec = VideoCodec.Default;

            _Writer.Open(_FilePath + _FileName);

            if (_RecordingScreen)
            {
                _ScreenSource.FrameInterval = 20;
                _ScreenSource.NewFrame     += Screen_NewFrame;
                _ScreenSource.Start();
            }

            if (_RecordingMicrophone)
            {
                _AudioSource           = new AudioCaptureDevice(_CurrenrAudioDevice);
                _AudioSource.NewFrame += new EventHandler <Accord.Audio.NewFrameEventArgs>(Microphone_NewFrame);
                _AudioSource.Start();
            }
            if (_RecordingAudio)
            {
                Trace.WriteLine("start recoder Speaker");
                _SpeakerSource           = new AudioCaptureDevice(_CurrenrSpeakerDevice);
                _SpeakerSource.NewFrame += new EventHandler <Accord.Audio.NewFrameEventArgs>(Speaker_NewFrame);
                _SpeakerSource.Start();
            }
        }
        /// <summary>
        ///   Starts recording. Only works if the player has
        ///   already been started and is grabbing frames.
        /// </summary>
        ///
        public void StartRecording()
        {
            if (IsRecording || !IsPlaying)
            {
                return;
            }

            Rectangle area     = CaptureRegion;
            string    fileName = newFileName();

            int height       = area.Height;
            int width        = area.Width;
            int framerate    = 1000 / screenStream.FrameInterval;
            int videoBitRate = 1200 * 1000;
            int audioBitRate = 320 * 1000;

            OutputPath         = Path.Combine(main.CurrentDirectory, fileName);
            RecordingStartTime = DateTime.MinValue;
            videoWriter        = new VideoFileWriter();

            // Create audio devices which have been checked
            var audioDevices = new List <AudioCaptureDevice>();

            foreach (var audioViewModel in AudioCaptureDevices)
            {
                if (!audioViewModel.Checked)
                {
                    continue;
                }

                var device = new AudioCaptureDevice(audioViewModel.DeviceInfo);
                device.AudioSourceError += device_AudioSourceError;
                device.Format            = SampleFormat.Format16Bit;
                device.SampleRate        = Settings.Default.SampleRate;
                device.DesiredFrameSize  = 2 * 4098;
                device.Start();

                audioDevices.Add(device);
            }

            if (audioDevices.Count > 0) // Check if we need to record audio
            {
                audioDevice = new AudioSourceMixer(audioDevices);
                audioDevice.AudioSourceError += device_AudioSourceError;
                audioDevice.NewFrame         += audioDevice_NewFrame;
                audioDevice.Start();

                videoWriter.Open(OutputPath, width, height, framerate, VideoCodec.H264, videoBitRate,
                                 AudioCodec.MP3, audioBitRate, audioDevice.SampleRate, audioDevice.Channels);
            }
            else
            {
                videoWriter.Open(OutputPath, width, height, framerate, VideoCodec.H264, videoBitRate);
            }

            HasRecorded = false;
            IsRecording = true;
        }
        private void initalizeAudioStuff()
        {
            try
            {
                AudioSource = new AudioCaptureDevice();
                AudioDeviceInfo info = null;
                var             adc  = new AudioDeviceCollection(AudioDeviceCategory.Capture);
                foreach (var ad in adc)
                {
                    string desc = ad.Description;
                    if (desc.IndexOf("Audio") > -1)
                    {
                        info = ad;
                    }
                }
                if (info == null)
                {
                    AudioSource = new AudioCaptureDevice();
                }
                else
                {
                    AudioSource = new AudioCaptureDevice(info);
                }

                //AudioCaptureDevice source = new AudioCaptureDevice();
                AudioSource.DesiredFrameSize = 4096;
                AudioSource.SampleRate       = 44100;
                //int sampleRate = 44100;
                //int sampleRate = 22050;

                AudioSource.NewFrame += AudioSource_NewFrame;
                // AudioSource.Format = SampleFormat.Format64BitIeeeFloat;
                AudioSource.AudioSourceError += AudioSource_AudioSourceError;
                // AudioSource.Start();
                int x = 1;
            }
            catch
            {
            }

            // Create buffer for wavechart control
            current = new float[AudioSource.DesiredFrameSize];

            // Create stream to store file
            stream  = new MemoryStream();
            encoder = new WaveEncoder(stream);

            frames  = 0;
            samples = 0;



            // Start
            AudioSource.Start();
        }
 public void StartRecord()
 {
     if (!isRecording)
     {
         StartTick   = null;
         isRecording = true;
         video.Open(@"D:\Projects\new_test.avi", 1920, 1080, new Accord.Math.Rational(60.0), VideoCodec.Default);
         captureStream.Start();
         audio.Start();
     }
 }
        public void Start()
        {
            _recognizer.Recognizing         += OnSpeechRecognized;
            _recognizer.Recognized          += OnSpeechRecognized;
            _recognizer.SpeechStartDetected += OnSpeechStartDetected;
            _recognizer.Canceled            += OnRecognitionCancelled;

            _recognizer.StartContinuousRecognitionAsync().Wait();
            _audioCapture.NewFrame += OnAudioFrameCaptured;
            _audioCapture.Start();
            _stopwatch.Start();
        }
Exemple #6
0
        /// <summary>
        ///   Starts recording audio from the sound card
        ///   开始从声卡录制音频
        /// </summary>
        ///
        private void BtnRecord_Click(object sender, EventArgs e)
        {
            // Create capture device
            //[1]创建本地音频捕获设备
            #region 本地音频捕获设备

            /*
             * 本地音频捕获设备(即麦克风)的音频源。
             * 备考:此accord.audio.iaudiosource捕获从本地音频获取的音频数据
             * 捕获设备,如麦克风。使用DirectSound捕获音频
             * 通过slimdx。//有关如何列出捕获设备的说明,
             * 请参见accord.directsound.audioDeviceCollection//文档页。
             */
            #endregion
            source = new AudioCaptureDevice()
            {
                //获取或设置所需的帧大小。
                //监听22050赫兹
                // Listen on 22050 Hz
                DesiredFrameSize = 4096,
                SampleRate       = 22050,

                #region 我们将读取16位PCM(脉冲编码调制)
                //我们将读取16位PCM(脉冲编码调制)
                // We will be reading 16-bit PCM
                //PCM 即脉冲编码调制 (Pulse Code Modulation)。
                //https://baike.baidu.com/item/pcm%E7%BC%96%E7%A0%81/10865033?fr=aladdin
                #endregion

                Format = SampleFormat.Format16Bit
            };

            // Wire up some events
            //注册音频资源事件
            source.NewFrame         += source_NewFrame;
            source.AudioSourceError += source_AudioSourceError;

            // Create buffer for wavechart control
            //每帧上要读取的样本量。
            Current = new float[source.DesiredFrameSize];

            // Create stream to store file
            //创建流以存储文件
            stream  = new MemoryStream();
            encoder = new WaveEncoder(stream);

            // Start
            source.Start();
            updateButtons();
        }
Exemple #7
0
        private void StartVoiceCapture(string fileName)
        {
            AudioCapture = new AudioCaptureDevice(new Guid(Properties.UserSettings.Default.Microphone));
            // Specify capturing options
            AudioCapture.DesiredFrameSize = 4096;
            AudioCapture.SampleRate       = 44100;

            AudioCapture.NewFrame         += NewAudioFrame;
            AudioCapture.AudioSourceError += AudioError;

            _audioStream = new FileStream(baseDirectory + "AppFiles/TempFiles/" + fileName, FileMode.Create);
            _waveEncoder = new WaveEncoder(_audioStream);

            AudioCapture.Start();
        }
Exemple #8
0
        public async void RecordAudioToFile(string _path = "1.wav")
        {
            if (_microphone == null)
            {
                SetRecorder();
            }
            if (FinishRecord == null)
            {
                throw new Exception("FinishRecord function not set!");
            }
            if (_path == null)
            {
                throw new ArgumentNullException("Error! Argument path is null!");
            }
            else if (_path != "1.wav")
            {
                RecordPath = _path;
            }


            Task t = new Task(OnListeningAsync);

            try
            {
                _fileStream = new FileStream(RecordPath, FileMode.OpenOrCreate, FileAccess.Write);
                _audioSaver = new WaveEncoder();
                _audioSaver.Open(_fileStream);
                IsRecordContinue = true;
                _microphone.Start();
                t.Start();
                await t;
                _microphone.WaitForStop();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                t.Dispose();
                _microphone.Dispose();
                _audioSaver?.Close();
                _fileStream?.Close();
                IsRecordContinue = false;
            }
        }
Exemple #9
0
        public void StartCapturing()
        {
            if (videoCaptureDevices.Count < 0)
            {
                return;
            }

            videoCaptureDevice = new VideoCaptureDevice(videoCaptureDevices[0].MonikerString);

            audioCaptureDevice = GetProperAudioDevice();

            ProbeVideoDevice();

            videoCaptureDevice.NewFrame += CaptureVideoDeviceNewFrame;
            videoCaptureDevice.Start();

            audioCaptureDevice.NewFrame += AudioCaptureDeviceNewFrame;
            audioCaptureDevice.Start();
        }
Exemple #10
0
        public void startRecording()
        {
            isRecording = true;



            int screenWidth  = (int)System.Windows.SystemParameters.PrimaryScreenWidth * 2;
            int screenHeight = (int)System.Windows.SystemParameters.PrimaryScreenHeight * 2;

            bmpScreenShot = new Bitmap(screenWidth, screenHeight);

            vf.Open(filename, screenWidth, screenHeight, 25, VideoCodec.Default, 400000);

            myCaptureThread = new Thread(new ThreadStart(captureFunction));
            myCaptureThread.Start();

            // Start
            AudioSource.Start();
        }
Exemple #11
0
        /// <summary>
        /// Create capture buffer, output wave file and stream recorded samples to disk every 50 milliseconds
        /// </summary>
        public void StreamAudio()
        {
            AudioListener.Position    = new Vector3D(0, 0, 0);
            AudioListener.Velocity    = new Vector3D(0, 0, 0);
            AudioListener.Orientation = new Orientation(new Vector3D(1, 1, 0), new Vector3D(0, 1, 0));
            Byte[] recordedData = null;

            AudioFormatEnum HQcaptureFormat     = AudioFormatEnum.Stereo16;
            int             HQcaptureFrequency  = 44100;
            int             HQcaptureBufferSize = 1028000;

            //Console.WriteLine("Creating File {0}", Environment.CurrentDirectory + "\\test.wav");

            if (_FileName == "")
            {
                _FileName = "undefined.wav";
            }

            WaveFileWriter wave = new WaveFileWriter();

            wave.CreateFile(_FileName, HQcaptureFormat);

            using (AudioCaptureDevice g = new AudioCaptureDevice(null, HQcaptureFormat, HQcaptureFrequency, HQcaptureBufferSize))
            {
                //Console.WriteLine("Started Recording (press Enter To Stop)");
                g.Start();

                while (OpenALRecoding)
                {
                    Thread.Sleep(50);
                    int samplecount = g.AvaliabeSampleCount;
                    recordedData = g.CaptureSamples();
                    wave.WriteCaptured(recordedData);
                }

                g.Stop();
                //Console.WriteLine("Stopped Recording");
            }
            wave.CloseFile();
            //Console.WriteLine("File Saved");
        }
Exemple #12
0
        /// <summary>
        ///   Starts recording. Only works if the player has
        ///   already been started and is grabbing frames.
        /// </summary>
        ///
        public void StartRecording()
        {
            if (IsRecording || !IsPlaying)
            {
                return;
            }

            Rectangle area     = CaptureRegion;
            string    fileName = NewFileName();

            int      height         = area.Height;
            int      width          = area.Width;
            Rational framerate      = new Rational(1000, screenStream.FrameInterval);
            int      videoBitRate   = 1200 * 1000;
            int      audioBitRate   = 320 * 1000;
            int      audioFrameSize = 10 * 4096;

            OutputPath                           = Path.Combine(main.CurrentDirectory, fileName);
            RecordingStartTime                   = DateTime.MinValue;
            videoWriter                          = new VideoFileWriter();
            videoWriter.BitRate                  = videoBitRate;
            videoWriter.FrameRate                = framerate;
            videoWriter.Width                    = width;
            videoWriter.Height                   = height;
            videoWriter.VideoCodec               = VideoCodec.H264;
            videoWriter.VideoOptions["crf"]      = "18"; // visually lossless
            videoWriter.VideoOptions["preset"]   = "veryfast";
            videoWriter.VideoOptions["tune"]     = "zerolatency";
            videoWriter.VideoOptions["x264opts"] = "no-mbtree:sliced-threads:sync-lookahead=0";

            // Create audio devices which have been checked
            var audioDevices = new List <AudioCaptureDevice>();

            foreach (var audioViewModel in AudioCaptureDevices)
            {
                if (!audioViewModel.Checked)
                {
                    continue;
                }

                var device = new AudioCaptureDevice(audioViewModel.DeviceInfo);
                device.AudioSourceError += Device_AudioSourceError;
                device.Format            = SampleFormat.Format32BitIeeeFloat;
                device.SampleRate        = Settings.Default.SampleRate;
                device.DesiredFrameSize  = audioFrameSize;
                device.Start();

                audioDevices.Add(device);
            }

            if (audioDevices.Count > 0) // Check if we need to record audio
            {
                audioMixer = new AudioSourceMixer(audioDevices);
                audioMixer.AudioSourceError += Device_AudioSourceError;
                audioMixer.NewFrame         += AudioDevice_NewFrame;
                audioMixer.Start();

                videoWriter.AudioBitRate = audioBitRate;
                videoWriter.AudioCodec   = AudioCodec.Aac;
                videoWriter.AudioLayout  = audioMixer.NumberOfChannels == 1 ? AudioLayout.Mono : AudioLayout.Stereo;
                videoWriter.FrameSize    = audioFrameSize;
                videoWriter.SampleRate   = audioMixer.SampleRate;
            }

            //this.lastFrameTime = DateTime.MinValue;

            videoWriter.Open(OutputPath);

            HasRecorded = false;
            IsRecording = true;
        }