Record from a Microphone Tutorial - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This is a tutorial on how to record from a microphone and save it on your computer in Visual Basic .NET

Create a new form and add 3 button to your form:

Rename the buttons as the following: Record, Save and Play

record from a microphone from visual basic .net

Go to the code page and add the following declaration:

Private Declare Function record Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer

Record Button Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        record("open new Type waveaudio Alias recsound", "", 0, 0)
         record("record recsound", "", 0, 0)
    End Sub

Stop and Save Button Code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        record("save recsound c:\mic.wav", "", 0, 0)
        record("close recsound", "", 0, 0)
    End Sub

You can change the above path to your specified folder location

Play Button Code:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        My.Computer.Audio.Play("c:\mic.wav", AudioPlayMode.Background)
    End Sub


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.