コード例 #1
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
コード例 #2
0
ファイル: Program.cs プロジェクト: WorkingRobot/ScreenCaster
 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();
 }
コード例 #3
0
ファイル: LSDevice.cs プロジェクト: Wessie/Loopstream
        public bool test()
        {
            tested = true;
            wf     = null;
            try
            {
                if (mm == null)
                {
                    return(false);
                }
                NAudio.Wave.IWaveIn dev = null;

                capt1 = mm.FriendlyName;       // windows name
                capt2 = mm.DeviceFriendlyName; // just device
                if (capt1.EndsWith(capt2 + ")"))
                {
                    capt1 = capt1.Substring(0, capt1.Length - (capt2.Length + 3));
                }
                isRec  = mm.DataFlow == NAudio.CoreAudioApi.DataFlow.All || mm.DataFlow == NAudio.CoreAudioApi.DataFlow.Capture;
                isPlay = mm.DataFlow == NAudio.CoreAudioApi.DataFlow.All || mm.DataFlow == NAudio.CoreAudioApi.DataFlow.Render;

                dev       = isPlay
                    ? dev = new NAudio.Wave.WasapiLoopbackCapture(mm)
                    : dev = new NAudio.CoreAudioApi.WasapiCapture(mm);

                if (dev != null)
                {
                    wf = dev.WaveFormat;
                    makeSerializationData();
                    dev.Dispose();
                    return(true);
                }
            }
            catch
            {
                mm = null;
            }
            return(false);
        }
コード例 #4
0
 public PlaybackRecorder(NAudio.CoreAudioApi.MMDevice device)
 {
     capture = new NAudio.Wave.WasapiLoopbackCapture(device);
     capture.DataAvailable += capture_DataAvailable;
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: Vamic/QuickRecord
        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();
            }
        }