簡體   English   中英

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

[英]How do I record audio in C# (Visual Studio 2017) on Windows 10?

我已經查看了有關此主題的先前問題和答案(使用 C#.net 的語音記錄 (winmm.dll) )。 正如作者所說,它不適用於某些操作系統。

當我在 Windows 10 (VS 2017) 上使用推薦的代碼時,它運行沒有錯誤,但沒有創建文件。

正如建議的那樣,我在文件位置使用了雙引號,但它仍然不起作用。

我還確認麥克風正在工作(我使用聽寫輸入這個問題)。

在 Windows 10 上錄制 C# 2017 中的音頻有什么建議嗎?

為了更有效地處理問題,也許您可以提供您嘗試過的代碼。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM