-1

help me I want to make a program that record mic in vb.net I got this code but I cant save audio on different location

Imports System.Runtime.InteropServices
Public Class Form1
'Dim recording As Boolean = False
Dim Filez As String = "C:\rec.mp3"

<DllImport("winmm.dll")>
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As String, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function

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

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    My.Computer.Audio.Play(Filez)
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    mciSendString("save recsound " & Filez, "", 0, 0)
    mciSendString("close recsound ", "", 0, 0)
    Button2.Enabled = True
End Sub
End Class

When i change path of Filez for save at another place it show error Error Image is Here

Please help

Mohmmad Yahya
  • 49
  • 1
  • 7

2 Answers2

0

You just need to launch your application with administrator rights.

Jomtek
  • 1
0

because there is a space in the new file path try this the full code will be all mciSendString function commands here https://msdn.microsoft.com/en-us/library/windows/desktop/dd743572(v=vs.85).aspx

Imports System.Runtime.InteropServices
Public Class Form1
    Dim Filez As String = ""
    Dim isrecording As Boolean = False
    <DllImport("winmm.dll")>
    Private Shared Function mciSendString(ByVal command As String, ByVal buffer As String, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Not (isrecording) Then
            mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
            mciSendString("record recsound", "", 0, 0)
            Button1.Text = "pause"
            isrecording = True
        Else
            mciSendString("pause recsound ", "", 0, 0)
            Button1.Text = "record"
            isrecording = False
        End If

        Button3.Enabled = True
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim savedialouge As New SaveFileDialog
        savedialouge.Filter = "wav file|*.wav"
        If savedialouge.ShowDialog = Windows.Forms.DialogResult.OK Then
            Filez = savedialouge.FileName    
            mciSendString("save recsound " & """" + Filez + """", "", 0, 0)
            mciSendString("close recsound ", "", 0, 0)
            Button1.Text = "new record"
            Button2.Enabled = True
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        My.Computer.Audio.Play(Filez)
    End Sub


End Class