在 C# 中从麦克风获取数据

发布于 2024-09-02 02:17:26 字数 69 浏览 4 评论 0原文

我正在尝试从麦克风(或线路输入)录制音频数据,然后使用 C# 再次重播。

关于如何实现这一目标有什么建议吗?

I'm trying to record audio data from a microphone (or line-in), and then replay it again, using C#.

Any suggestions on how I can achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜吻♂芭芘 2024-09-09 02:17:26

请参阅控制台和多线程录制和播放

class Program
{

    static void Main(string[] args)
    {
        rex.Data += new RecorderEx.DataEventHandler(rex_Data);
        rex.Open += new EventHandler(rex_Open);
        rex.Close += new EventHandler(rex_Close);
        rex.Format = pcmFormat;
        rex.StartRecord();
        Console.WriteLine("Please press enter to exit!");
        Console.ReadLine();
        rex.StopRecord();
    }

    static RecorderEx rex = new RecorderEx(true);
    static PlayerEx play = new PlayerEx(true);
    static IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(1, 16, 44100);

    static void rex_Open(object sender, EventArgs e)
    {
        play.OpenPlayer(pcmFormat);
        play.StartPlay();
    }

    static void rex_Close(object sender, EventArgs e)
    {
        play.ClosePlayer();
    }

    static void rex_Data(object sender, DataEventArgs e)
    {
        byte[] data = e.Data;
        play.AddData(data);
    }
}

See Console and multithreaded recording and playback

class Program
{

    static void Main(string[] args)
    {
        rex.Data += new RecorderEx.DataEventHandler(rex_Data);
        rex.Open += new EventHandler(rex_Open);
        rex.Close += new EventHandler(rex_Close);
        rex.Format = pcmFormat;
        rex.StartRecord();
        Console.WriteLine("Please press enter to exit!");
        Console.ReadLine();
        rex.StopRecord();
    }

    static RecorderEx rex = new RecorderEx(true);
    static PlayerEx play = new PlayerEx(true);
    static IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(1, 16, 44100);

    static void rex_Open(object sender, EventArgs e)
    {
        play.OpenPlayer(pcmFormat);
        play.StartPlay();
    }

    static void rex_Close(object sender, EventArgs e)
    {
        play.ClosePlayer();
    }

    static void rex_Data(object sender, DataEventArgs e)
    {
        byte[] data = e.Data;
        play.AddData(data);
    }
}
云淡风轻 2024-09-09 02:17:26

NAudio 的实时链接。

https://github.com/naudio/NAudio

它以 NuGet 包的形式提供

有关输出设备的信息:

https://github.com/naudio/NAudio/blob/master/ Docs/OutputDeviceTypes.md

请记住常见问题解答中的以下性能:

“.NET 性能对于音频来说是否足够好?

虽然 .NET 无法与非托管语言竞争极低延迟的音频工作,但它的性能仍然优于许多人会期望在一台相当普通的 PC 上,您可以轻松地将多个 WAV 文件混合在一起,包括将它们传递给各种效果和编解码器,以大约 50 毫秒的延迟进行无故障播放。”

A live link of NAudio.

https://github.com/naudio/NAudio

It's available as a NuGet Package

Information about Output devices:

https://github.com/naudio/NAudio/blob/master/Docs/OutputDeviceTypes.md

Keep in mind for performance the following from the FAQ:

"Is .NET Performance Good Enough for Audio?

While .NET cannot compete with unmanaged languages for very low latency audio work, it still performs better than many people would expect. On a fairly modest PC, you can quite easily mix multiple WAV files together, including pass them through various effects and codecs, play back glitch free with a latency of around 50ms."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文