コード例 #1
0
        private void BtnStart_Click(object sender, EventArgs e)
        {
            StartRecording();
            RestartRecording.Start();

            pnlSettings.Visible = false;

            btnStart.Enabled = false;
            btnStop.Enabled  = true;
        }
コード例 #2
0
        private void StopRecording()
        {
            RestartRecording.Stop();

            if (CaptureInstance != null && RecordedAudioWriter != null)
            {
                // Stop audio recording
                CaptureInstance.StopRecording();
                this.RecordedAudioWriter.Dispose();
                this.RecordedAudioWriter = null;
                CaptureInstance.Dispose();
            }

            FileCount++;

            pnlRecording.Visible = false;

            SaveAudio();
        }
コード例 #3
0
        private void StartRecording()
        {
            string outputFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $@"\ASP\Temp\temp_audio_{FileCount}.wav";

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

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

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

            CaptureInstance.StartRecording();

            pnlRecording.Visible = true;

            pnlRecording.Visible = true;

            RestartRecording.Start();
        }