首先添加命名空间和相关的代码,如下:

using System.Runtime.InteropServices;

 [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
        private static extern int mciSendString(
         string lpstrCommand,
         string lpstrReturnString,
         int uReturnLength,
         int hwndCallback
        );

        private static void mciSendString(String cmd)
        {
            mciSendString(cmd, "", 0, 0);
        }

        private static void StartRecord()
        {
            mciSendString("close movie");
            mciSendString("open new type WAVEAudio alias movie");
            mciSendString("record movie");
        }

        private static void StopRecord(string filename)
        {
            mciSendString("stop movie");
            mciSendString("save movie " + filename);
            mciSendString("close movie");
        }

 然后直接调用 StartRecord(),开始录音 StopRecord():停止录音

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2022-01-13
  • 2021-09-29
  • 2022-01-12
  • 2021-07-20
  • 2021-12-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-03
  • 2021-07-17
  • 2021-06-13
相关资源
相似解决方案