我想录制系统声音,例如Windows错误声音或蜂鸣声,要实现这一点,我可以录制输出声音(扬声器声音),但是唯一可以使用的是mcistring
:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
<DllImport("winmm.dll")>
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, 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
Try
Dim i As Integer
i = mciSendString("open new type waveaudio alias capture", Nothing, 0, 0)
Console.WriteLine(i)
i = mciSendString("set capture input 0", Nothing, 0, 0)
Console.WriteLine(i)
i = mciSendString("record capture", Nothing, 0, 0)
Console.WriteLine(i)
Me.Label1.Text = "Recording"
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim i As Integer
i = mciSendString("save capture " & "C:\Users\Djordje\Desktop\xvw.wav", Nothing, 0, 0)
i = mciSendString("close capture", Nothing, 0, 0)
Me.Label1.Text = "Idle"
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Console.Beep()
End Sub
End Class
但是它会记录默认的 input 声音(麦克风),并且我需要PC产生的“内部”声音...我在几个论坛上发现可以选择要使用的设备,但是它们没有显示任何代码,我也不知道如何。
https://docs.microsoft.com/en-gb/windows/desktop/Multimedia/set
我在上面的文章中读到了set input
的内容,但是它说您可以按整数选择设备,或者默认情况下它将选择任何可用的设备,但是当我在不设置输入且未插入麦克风的情况下运行代码时,我会得到一个空白wav文件...
所以我不确定mcistring是否可以录制输出声音,但是如果可能的话,我想使用它而不是其他一些库,我想使其尽可能简单。谢谢