帮助我,我想制作一个在vb.net中录制麦克风的程序我得到了这段代码,但我不能在不同的位置保存音频
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
请帮忙
答案 0 :(得分:0)
您只需要以管理员权限启动您的应用程序。
答案 1 :(得分:0)
因为新文件路径中有空格 试试这个完整的代码 这里所有的mciSendString函数命令 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