代码之家  ›  专栏  ›  技术社区  ›  paxdiablo

如何使用C#/WPF录制音频?

  •  4
  • paxdiablo  · 技术社区  · 15 年前

    我有一个应用程序,我想添加的能力,导入小音频片段直接从麦克风设备的某种类型。

    不过,音频略有不同。我已经允许从磁盘导入音频文件,但我想添加直接从麦克风录制到磁盘文件或内存缓冲区的功能。

    C#/WPF是否提供了一种简单的方法?添加此功能的好方法是什么?

    4 回复  |  直到 15 年前
        1
  •  21
  •   Darin Dimitrov    15 年前

    mciSendString 功能:

    public class Program
    {
        [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
    
        static void Main(string[] args)
        {
            mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
            mciSendString("record recsound", "", 0, 0);
            Console.WriteLine("recording, press Enter to stop and save ...");
            Console.ReadLine();
    
            mciSendString("save recsound c:\\work\\result.wav", "", 0, 0);
            mciSendString("close recsound ", "", 0, 0);
        }
    }
    

    DirectShowNet 图书馆(有一个 sample 打电话 PlayCap ).

    你也可以找到这个 CodeProject article 有用。

        3
  •  1
  •   CodesInChaos    15 年前

    我正在使用这个库: http://www.codeproject.com/KB/cs/Streaming_wave_audio.aspx 主要是因为简单的api。但我不太喜欢这个代码。例如,它在很长一段时间内修复内存中的缓冲区,而不是分配非托管缓冲区。

        4
  •  1
  •   unkown    10 年前