[英]How do I record audio in C# (Visual Studio 2017) on Windows 10?
I have reviewed the previous question and answer on this topic ( voice record (winmm.dll) using C#.net ).我已经查看了有关此主题的先前问题和答案(使用 C#.net 的语音记录 (winmm.dll) )。 As the author says, it does not work on certain OS's.
正如作者所说,它不适用于某些操作系统。
When I use the recommended code on Windows 10 (VS 2017), it runs without error but creates no files.当我在 Windows 10 (VS 2017) 上使用推荐的代码时,它运行没有错误,但没有创建文件。
As suggested, I used double quotes in the file location but it still does not work.正如建议的那样,我在文件位置使用了双引号,但它仍然不起作用。
I have also confirmed that the microphone is working (I used dictation typing this question).我还确认麦克风正在工作(我使用听写输入这个问题)。
Any suggestions for recording audio in C# 2017 on Windows 10?在 Windows 10 上录制 C# 2017 中的音频有什么建议吗?
To handle the issue more efficiently, maybe you can provide the code that you have tried.为了更有效地处理问题,也许您可以提供您尝试过的代码。
The mciSendString
works fine in my test, please refer to the following demo. mciSendString
在我的测试中运行良好,请参考以下演示。
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int mciSendString(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
);
private void btnStart_Click(object sender, EventArgs e)
{
mciSendString("open new type WAVEAudio alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);
}
private void btnStop_Click(object sender, EventArgs e)
{
mciSendString("stop recsound", "", 0, 0);
mciSendString("save recsound D://temp.wav", "", 0, 0);
mciSendString("close recsound", "", 0, 0);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.