pax*_*blo 6 c# wpf audio-recording
我有一个应用程序,我想添加直接从某种麦克风设备导入小音频片段的功能.
我已经允许导入图片了,这对磁盘文件和摄像头来说还可以,因为当你附加它们时,摄像机会神奇地变成磁盘设备,所以文件导入方法适用于两者.
但音频略有不同.我已经允许从磁盘导入音频文件,但我想添加从麦克风直接录制到磁盘文件或内存缓冲区的功能.
C#/ WPF提供了一种简单的方法吗?添加此功能的好方法是什么?
Dar*_*rov 19
可能最简单的方法是使用mciSendString函数:
public class Program
{
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
static void Main(string[] args)
{
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);
Console.WriteLine("recording, press Enter to stop and save ...");
Console.ReadLine();
mciSendString("save recsound c:\\work\\result.wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用DirectShowNet库(有一个名为的样本PlayCap).
您可能还会发现此CodeProject文章很有用.
| 归档时间: |
|
| 查看次数: |
29294 次 |
| 最近记录: |