简体   繁体   中英

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 ). 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.

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?

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.

[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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM