Sound card recording: Collect sound from your sound card and record it as a MP3 file!

Source: Internet
Author: User

Sound card Recording is a common requirement, such as watching a video or listening to a song online, and feeling that a piece of music is particularly good, but without downloading it, we can use the sound card recording technology to record it while playing.

Achieve sound card recording, involving two basic technologies: the sound card captures and records sound into a mp3 file. The Voice video capture component Mcapture provides the ability to collect sound cards, while the Voice video recording component Mfile provides the ability to generate MP3 files for sound data recording. So, combining mcapture and mfile to combine them, we can implement the software we want.

This article implements a simple sound card recorded by the Demo,demo after running it as follows:


After you stop recording, a file named Test.mp3 is generated in the running directory, and then we can play it using a variety of players, such as the QQ music player. Next, let's look at the detailed implementation of this demo.

        Private Isoundcardcapturer Soundcardcapturer;           Private Audiofilemaker Audiofilemaker;        Private volatile bool isrecording = false;                Start the sound card acquisition, recording private void Button1_Click (object sender, EventArgs e) {try { According to the sound card collector "current sound card acquisition supports only Vista and above systems" This.soundcardcapturer = Capturerfactory.createsoundcardcaptur                ER ();                this.soundcardCapturer.AudioCaptured + = new esbasic.cbgeneric<byte[]> (soundcardcapturer_audiocaptured);                This.soundcardCapturer.CaptureError + = new cbgeneric<exception> (microphonecapturer_captureerror);                Start collecting sound card this.soundcardCapturer.Start ();                This.audiocount = 0;                              This.audiofilemaker = new Audiofilemaker (); This.audioFileMaker.Initialize ("Test.mp3", Audiocodectype.mp3, This.soundcardCapturer.SampleRate,                This.soundcardCapturer.ChannelCount); THis.isrecording = true;                this.button_startRecord.Enabled = false;                               This.button_stopRecord.Enabled = true; This.label_recording.            Visible = true; } catch (Exception ee) {MessageBox.Show (EE.            Message);            }}//Stop sound card capture, stop recording private void Button2_Click (object sender, EventArgs e) {try {this.                Cursor = Cursors.waitcursor; Cbgeneric cb = new Cbgeneric (this.                Stoprecordasyn); Cb.            BeginInvoke (null, NULL); } catch (Exception ee) {MessageBox.Show (EE.            Message);            }} private void Stoprecordasyn () {this.isrecording = false;            This.soundcardCapturer.Stop (); This.soundcardCapturer.Dispose ();            You have to release the sound card collector!!!!!!!!            This.audioFileMaker.Close (TRUE); This.audioFileMaker.DispoSE ();            This.audiofilemaker = null; This.        Afterstoprecord (); private void Afterstoprecord () {if (this. invokerequired) {this. BeginInvoke (New Cbgeneric (this.            Afterstoprecord));                } else {this.button_startRecord.Enabled = true;                               this.button_stopRecord.Enabled = false; This.label_recording.                Visible = false; This.                Cursor = Cursors.Default; MessageBox.Show ("Recording done! "+ (This.audiocount * 0.05). ToString () + "seconds.            ");        }} private int audiocount = 0;                void Soundcardcapturer_audiocaptured (byte[] audiodata)//acquired voice data {if (this.isrecording) {                This.audioFileMaker.AddAudioFrame (Audiodata);            ++this.audiocount; }} void Microphonecapturer_captureerror (Exception obj) {} private void Form1_formclosing (object sender, FormClosingEventArgs e) {if (this.isrecording) { MessageBox.Show ("Recording video, please stop first!")                ");                E.cancel = true;            Return      }                   }

For a typical machine, the basic information for the audio data obtained by the Mcapture acquisition sound card is this:

(1) Bit number: 16

(2) channel number: 2

(3) sample rate: 48000

(4) mcapture triggers a audiocaptured event every 50 milliseconds.

It is important to note that when initializing the Mfile Audiofilemaker (that is, calling its Initialize method), the incoming sample rate and the number of channels must be The Samplerate and Channelcount properties of the Isoundcardcapturer.

Download the sound card recording demo Source: Recordsoundcarddemo.rar



Sound card recording: Collect sound from your sound card and record it as a MP3 file!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.