Page 1 of 1

How to Create a Sound Recorder

Posted: Thu Mar 03, 2011 9:36 pm
by GoodGuy17
Hello,

In this tutorial, we are going to learn how to create a sound recorder. Now, note this: this WILL NOT be a professional sound recording application, just a simple Record/Stop/Play recorder. Credits for me learning this: YouTube (forgot which video :? maybe someone else can find it)

Let's Go!

OK, start up Visual Basic. Title your program anything you want, but I will name mine "Sound Recorder".

Controls:

Object = Label, Name = Label1, Text = Ready..., Font = Default w/ Bold
Object = Button, Name = Button1, Text = Start
Object = Button, Name = Button2, Text = Stop
Object = Button, Name = Button3, Text = Play
Object = BackgroundWorker, Name = BackgroundWorker1

I organized my controls like in the picture below:
Image


Code:

Go into the code, and add this right under Public Class Form1:
Code: Select all
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstyCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
This code is calling the DLL called winmm so we can use it.

Go into the code for your Start button click event, and add this code:
Code: Select all
        'Enable Stop button
        Button2.Enabled = True
        'Disable Play button
        Button3.Enabled = False
        'Disable Start button
        Button1.Enabled = False
        'Start recording
        mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
        mciSendString("record recsound", "", 0, 0)
        'Show status
        Label1.Text = "Recording..."
Go into the code for the Stop button click event, and add this code:
Code: Select all
        'Enable Start button
        Button1.Enabled = True
        'Enable Play button
        Button3.Enabled = True
        'Disable Stop button
        Button2.Enabled = False
        'Save recording
        mciSendString("save recsound C:\record.wav", "", 0, 0)
        mciSendString("close recsound", "", 0, 0)
        'Show status
        Label1.Text = "Finished"
Go into the code for the Play button click event, and add this code:
Code: Select all
        'Show status
        Label1.Text = "Playing..."
        'Disable Play button
        Button3.Enabled = False
        'Disable Stop button
        Button2.Enabled = False
        'Disable Start button
        Button1.Enabled = False
        'Play recording
        Me.BackgroundWorker1.RunWorkerAsync()
Go into the code for the BackgroundWorker dowork event, and add this code:
Code: Select all
        'Play audio
        My.Computer.Audio.Play("C:\record.wav", AudioPlayMode.WaitToComplete)
        'Enable Start button
        Button1.Enabled = True
        'Disable Stop button
        Button2.Enabled = False
        'Enable Play button
        Button3.Enabled = True
        'Threading.Thread.Sleep
        Threading.Thread.Sleep(250)
Go into the code for the BackgroundWorker runworkercompleted event, and add this code:
Code: Select all
        'Show status
        Me.Label1.Text = "Done"
About:

I did not explain the code, because it is heavily commented. This should be good enough to learn this, as I commented it well, I think. Please +rep if you liked this!

~GoodGuy17 :D

Re: How to Create a Sound Recorder

Posted: Fri Mar 18, 2011 1:03 pm
by volttide
thanks, this project is work

Re: How to Create a Sound Recorder

Posted: Fri Mar 18, 2011 9:07 pm
by MrAksel
Finally someone posted here Reboh, but i have used this code a while but can i post the app here?

Re: How to Create a Sound Recorder

Posted: Fri Mar 18, 2011 10:03 pm
by GoodGuy17
Yea, sure. No credits needed (like, text, not Code Credits).

Re: How to Create a Sound Recorder

Posted: Sat Mar 19, 2011 8:40 am
by Skillful
Nice tutorial GoodGuy17! BTW did you actually use it in any of your apps?
+rep too :)

Re: How to Create a Sound Recorder

Posted: Sat Mar 19, 2011 8:44 am
by MrAksel
GoodGuy17 wrote:
Yea, sure. No credits needed (like, text, not Code Credits).
Ok thanks

Re: How to Create a Sound Recorder

Posted: Sun Mar 20, 2011 2:43 am
by GoodGuy17
CoderBoy1201 wrote:
Nice tutorial GoodGuy17! BTW did you actually use it in any of your apps?
+rep too :)
No, not really, but I was wanting to make a voice editing program once, and I could never figure out how to auto-tune.