gpt4 book ai didi

c# - 记录来自 NAudio WaveIn 的输入,并输出到 NAudio WaveOut

转载 作者:太空狗 更新时间:2023-10-29 18:13:55 25 4
gpt4 key购买 nike

我希望能够通过 NAudio.WaveIn 从麦克风设备获取输入,然后通过 NAudio.WaveOut 将准确的输入输出到输出设备。

我该怎么做?

最佳答案

这是对我有用的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.CoreAudioApi;

namespace WindowsFormsApplication1
{
public partial class Form4 : Form
{

private BufferedWaveProvider bwp;

WaveIn wi;
WaveOut wo;
public Form4()
{
InitializeComponent();
wo = new WaveOut();
wi = new WaveIn();

wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);

bwp = new BufferedWaveProvider(wi.WaveFormat);
bwp.DiscardOnBufferOverflow = true;

wo.Init(bwp);
wi.StartRecording();
wo.Play();

}

void wi_DataAvailable(object sender, WaveInEventArgs e)
{
bwp.AddSamples(e.Buffer, 0, e.BytesRecorded);

}
}
}

关于c# - 记录来自 NAudio WaveIn 的输入,并输出到 NAudio WaveOut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5694326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com