简体   繁体   English

如何在 Windows 10 上的 C# (Visual Studio 2017) 中录制音频?

[英]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.

相关问题 如何在 Visual Studio 2017 中使用 C# 使用 Selenium 查找和选择下拉值 - How do I find and select a dropdown value with Selenium using C# in Visual Studio 2017 如何在 Visual Studio 2017 中使用 C# 8? - How can I use C# 8 with Visual Studio 2017? 如何在Visual Studio 2017社区中为C#代码设置字体颜色? - How do I set font colors for C# code in Visual Studio 2017 Community? 如何在Visual C#或C ++中正确处理Windows 10应用程序的暂停? - How do I handle suspension of Windows 10 apps correctly in Visual C# or C++? 初始化 C# Visual Studio Windows 窗体应用程序后,如何更改窗体的视觉效果? - How do I change the visual of a form after it has Initialized C# Visual Studio Windows Form App? 在C#Visual Studio中连续录制和播放音频 - Continuous record and play audio in C# visual studio 如何使用C#/ WPF录制音频? - How do I record audio with C#/WPF? 如何在Visual Studio 2017的C#中启用代码建议功能? - How do you enable Code suggestion feature in C# in Visual Studio 2017? Visual Studio 2017 C# - 如何将本地 .txt 列表的内容导入 ComboBox 的选项? - Visual Studio 2017 C# - How do you import the contents of a local .txt list into a ComboBox's options? 如何在Visual Studio 2008中使用C#为其他窗口创建工作区窗口? - How do I create a workspace window for other windows using c# in visual studio 2008?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM