Example #1
0
        public void Record(string path)
        {
            waveWriter = new NAudio.Wave.WaveFileWriter(path, capture.WaveFormat);
            capture.StartRecording();

            recording = true;
        }
Example #2
0
        } // End Sub Main

        // https://ourcodeworld.com/articles/read/702/how-to-record-the-audio-from-the-sound-card-system-audio-with-c-using-naudio-in-winforms
        // https://stackoverflow.com/questions/18812224/c-sharp-recording-audio-from-soundcard
        static void TestAudioRecording()
        {
            // Define the output wav file of the recorded audio
            string outputFilePath = @"D:\username\Desktop\system_recorded_audio.wav";

            // Redefine the capturer instance with a new instance of the LoopbackCapture class
            NAudio.Wave.WasapiLoopbackCapture CaptureInstance = new NAudio.Wave.WasapiLoopbackCapture();

            // Redefine the audio writer instance with the given configuration
            NAudio.Wave.WaveFileWriter RecordedAudioWriter = new NAudio.Wave.WaveFileWriter(outputFilePath, CaptureInstance.WaveFormat);

            // When the capturer receives audio, start writing the buffer into the mentioned file
            CaptureInstance.DataAvailable += (s, a) =>
            {
                // Write buffer into the file of the writer instance
                RecordedAudioWriter.Write(a.Buffer, 0, a.BytesRecorded);
            };

            // When the Capturer Stops, dispose instances of the capturer and writer
            CaptureInstance.RecordingStopped += (s, a) =>
            {
                RecordedAudioWriter.Dispose();
                RecordedAudioWriter = null;
                CaptureInstance.Dispose();
            };

            // Start audio recording !
            CaptureInstance.StartRecording();


            System.Console.WriteLine(" --- Press any key to stop recording --- ");
            System.Console.ReadKey();
            CaptureInstance.StopRecording();
        } // End Sub Main
Example #3
0
 public static void Main()
 {
     SetConsoleCtrlHandler(new ConsoleEventDelegate(ConsoleEventCallback), true);
     waveIn                   = new NAudio.Wave.WasapiLoopbackCapture();
     waveFileWriter           = new NAudio.Lame.LameMP3FileWriter(@fileName, waveIn.WaveFormat, NAudio.Lame.LAMEPreset.STANDARD);
     waveIn.DataAvailable    += waveIn_DataAvailable;
     waveIn.RecordingStopped += waveIn_RecordingStopped;
     waveIn.StartRecording();
 }
Example #4
0
        private void HandleHotkey()
        {
            if (!recording)
            {
                sourceStream = new NAudio.Wave.WasapiLoopbackCapture();
                sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
                path = folderLocation.Text + "\\";
                filename = GetFileName(false);
                if (recordToMp3.Checked)
                {
                    filetype = ".mp3";
                    mp3Writer = new NAudio.Lame.LameMP3FileWriter(filename + filetype, sourceStream.WaveFormat, 128);
                }
                else
                {
                    filetype = ".wav";
                    waveWriter = new NAudio.Wave.WaveFileWriter(filename + filetype, sourceStream.WaveFormat);
                }

                sourceStream.StartRecording();
                recording = true;
                timer.Start();

                notifyIcon.BalloonTipText = "Started recording.";
                if (showNotifications.Checked)
                    notifyIcon.ShowBalloonTip(1000);

            }
            else
            {
                StopRecording();
            }
        }