Question Need Help with Microphone Active Levels Display?

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
I have got the program to record from the microphone and save it, while this works fine, what im trying to figure out is when the program is recording the voice of the user i would like it to display this in a ProgressBar to show the input moving up and down and the user speaks? any help would be apriciated.

Here's My full source
VB.NET:
Option Explicit On
Option Strict On
Imports System.Xml
Public Class frmMain
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Int32, ByVal hwndCallback As Int32) As Int32
    Dim intz As Integer
    Dim aFiles As String = ""
    Dim sPaths As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\HapCap\"

    Public Function CaptureScreen() As Bitmap
        Dim tempBmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        Dim grp As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(tempBmp)
        grp.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, System.Drawing.CopyPixelOperation.SourceCopy)
        Return tempBmp
    End Function

    Private Sub btnCapture_Click(sender As System.Object, e As System.EventArgs) Handles btnCapture.Click
        Select Case btnCapture.Text
            Case "Stop Capture"
                intz = 0
                btnCapture.Text = "Start Capture"
                Me.WindowState = FormWindowState.Normal
                If chkSound.Checked = False Then
                    mciSendString("save recsound " & sPaths & "SoundCap.wav", "", 0, 0)
                    mciSendString("close recsound", "", 0, 0)
                End If
                tmrREC.Stop()

            Case "Start Capture"
                btnCapture.Text = "Stop Capture"
                If chkMin.Checked = True Then
                    Me.WindowState = FormWindowState.Minimized
                End If
                If chkSound.Checked = False Then
                    mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
                    'Set audio properties
                    mciSendString("set recsound channels 1", CStr(0&), 0, 0)
                    mciSendString("set recsound samplespersec 11025", CStr(0&), 0, 0)
                    mciSendString("set recsound bitspersample 16", CStr(0&), 0, 0)
                    'Record from the beginning
                    mciSendString("seek recsound to start", CStr(0&), 0, 0)
                    mciSendString("record recsound", "", 0, 0)
                End If
                tmrREC.Start()

        End Select

    End Sub

    Private Sub tmrREC_Tick(sender As System.Object, e As System.EventArgs) Handles tmrREC.Tick
        If FileIO.FileSystem.DirectoryExists(sPaths) Then
            tmrREC.Interval = trkSpeed.Value
            intz = intz + 1
            picCapture.Image = CaptureScreen()
            picCapture.Image.Save(sPaths & "PicCap-" & Format(intz, "00") & ".jpg")
        Else
            MkDir(sPaths)
        End If
    End Sub

    Private Sub btnOpen_Click(sender As System.Object, e As System.EventArgs) Handles btnOpen.Click
        If FileIO.FileSystem.FileExists(sPaths & "PicCap-01.jpg") Then
            System.Diagnostics.Process.Start("explorer", sPaths)
        Else
            MsgBox("No Captures Present", MsgBoxStyle.OkOnly, "Happy Cap Message")
        End If
    End Sub

    Private Sub btnSettings_Click(sender As System.Object, e As System.EventArgs) Handles btnSettings.Click
        SaveSet()
        MsgBox("Settings Saved", MsgBoxStyle.OkOnly, "Settings")
    End Sub

    Private Sub SaveSet()
        My.Settings.Sound = CBool(chkSound.CheckState)
        My.Settings.Minimize = CBool(chkMin.CheckState)
        My.Settings.Speed = trkSpeed.Value
        My.Settings.Editor = cboEditor.Text
        My.Settings.Priview = CBool(chkPreview.CheckState)
        My.Settings.Save()
    End Sub

    Private Sub frmMain_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        SaveSet()
    End Sub

    Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.webTextScroll.Navigate("about:blank")
        Me.webTextScroll.Document.Write("<body bgcolor=""CornflowerBlue"" ><font face=""Microsoft Sans Serif""></body><marquee onMouseOver=""this.stop();"" onMouseOut=""this.start();"" scrolldelay=""0"" scrollamount=""5"" behavior=""scroll"" direction=""up""></img>Author: ProtekNickz<br><br>Date: 16/09/2011<br><br>Site: <a href=""http://www.proteknickz.dyns.cx"" target=""about:blank"">ProtekNickz</a><br><br><br><br>Happy Cap is a great free program for capturing your desktop events so you the user can edit the output files in a selected external editor, If you need further help with this program then please visit the site above provided.</marquee></font>")
        chkSound.Checked = My.Settings.Sound
        chkMin.Checked = My.Settings.Minimize
        trkSpeed.Value = My.Settings.Speed
        cboEditor.Text = My.Settings.Editor
        chkPreview.Checked = My.Settings.Priview
        txtRegister.Text = My.Settings.UserRegister

        HapCapSPLSH.lblRegTo.Text = "Registered to: " & Trim(My.Settings.UserRegister)
        If txtRegister.Text = "Enter email to register" Then
        ElseIf txtRegister.Text = "" Then
            txtRegister.Enabled = True
            btnRegister.Enabled = True
        Else
            txtRegister.Enabled = False
            btnRegister.Enabled = False
        End If

    End Sub

    Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
        aFiles = ""
        If FileIO.FileSystem.FileExists(sPaths & "PicCap-01.jpg") Then
            Kill(sPaths & "*.*")
            MsgBox("Capture Deleted", MsgBoxStyle.OkOnly, "Deleted")
        Else
            MsgBox("No Capture's to Delete", MsgBoxStyle.OkOnly, "None Deleted")
        End If
    End Sub

    Private Sub btnEditor_Click(sender As System.Object, e As System.EventArgs) Handles btnEditor.Click
        Dim txtEditor As String = ""
        GetFilez()
        If FileIO.FileSystem.FileExists(sPaths & "PicCap-01.jpg") Then
            Select Case cboEditor.Text
                Case "Windows Live Movie Maker"
                    txtEditor = "MovieMaker"
                Case "Sony Vegas Pro 10"
                    txtEditor = "vegas100"
            End Select
            My.Computer.FileSystem.CurrentDirectory = sPaths
            System.Diagnostics.Process.Start(txtEditor, aFiles)
        Else
            MsgBox("No Files to edit", MsgBoxStyle.OkOnly, "None to Edit")
        End If

    End Sub

    Private Sub pgrSound_Click(sender As System.Object, e As System.EventArgs) Handles pgrSound.Click
        pgrSound.Value = sSoundz.AudioMixerHelper.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE ' was just testing various codes
    End Sub

    Private Sub chkPreview_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chkPreview.CheckedChanged
        If chkPreview.CheckState = CheckState.Checked Then tabMain.TabPages.Remove(tabPreview)
        If chkPreview.CheckState = CheckState.Unchecked Then tabMain.TabPages.Insert(1, tabPreview)
    End Sub

    Public Sub GetFilez()
        Dim strFileSize As String = ""
        Dim di As New IO.DirectoryInfo(sPaths)
        Dim aryFi As IO.FileInfo() = di.GetFiles("*.*")
        Dim fi As IO.FileInfo
        For Each fi In aryFi
            aFiles += fi.Name.ToString & Chr(32)
        Next
    End Sub

    Private Sub btnRegister_Click(sender As System.Object, e As System.EventArgs) Handles btnRegister.Click
        txtRegister.Enabled = False
        btnRegister.Enabled = False
        My.Settings.UserRegister = txtRegister.Text
        My.Settings.Save()
    End Sub

    Private Sub lnkProtekNickz_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
        Process.Start("explorer", "http://www.proteknickz.dyns.cx")
    End Sub

End Class

Basically this program captures the screen to multiple captures and sound records if needed.

I'm still working on this...
 
I just checked and this return the mic device in my system:
device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia)

You could also use DevEnum.EnumerateAudioEndPoints to get capture devices if there are more of them.

Then, is in original CodeProject sample, to read volume/peak value into Progressbars you can use a Timer and read values from device.AudioMeterInformation, this can for example be MasterPeakValue (multiply value by 100, use default max value 100 in progressbar).
 
Back
Top