为了账号安全,请及时绑定邮箱和手机立即绑定

同时从两个输入设备录制音频并保存到波形文件中?

同时从两个输入设备录制音频并保存到波形文件中?

C#
白衣非少年 2023-08-27 10:25:08
我正在尝试同时在两个不同的设备上录制音频,并且文件的输出应保存在波形文件中使用 NAudio 我尝试解决问题,如下所示,但我仍然没有得到它WaveInEvent waveSource1 = new WaveInEvent();waveSource1.DeviceNumber = DeviceID1;waveSource1.WaveFormat = new WaveFormat(44100, 2);waveSource1.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);string tempFile1 = (@"C:\Users\Nirmalkumar\Desktop\speech1.wav");waveFile1 = new WaveFileWriter(tempFile1, waveSource1.WaveFormat);waveSource.StartRecording();waveSource1.StartRecording();Console.Beep();int milliseconds = 5000;Thread.Sleep(milliseconds);waveSource.StopRecording();waveSource1.StopRecording();这是第一个波源WaveInEvent waveSource = new WaveInEvent();    waveSource.DeviceNumber = DeviceID;    waveSource.WaveFormat = new WaveFormat(44100, 16, 2);    waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);    string tempFile = (@"C:\Users\Nirmalkumar\Desktop\speech.wav");    waveFile = new WaveFileWriter(tempFile, waveSource.WaveFormat);static void waveSource_DataAvailable(object sender, WaveInEventArgs e){    waveFile.Write(e.Buffer, 0, e.BytesRecorded);}
查看完整描述

1 回答

?
吃鸡游戏

TA贡献1829条经验 获得超7个赞

我正在尝试同时在两个不同的设备上录制音频,并且文件的输出应保存在波形文件中


使用 NAudio 我尝试解决问题,如下所示,但我仍然没有得到它


WaveInEvent waveSource1 = new WaveInEvent();

waveSource1.DeviceNumber = DeviceID1;

waveSource1.WaveFormat = new WaveFormat(44100, 2);

waveSource1.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);

string tempFile1 = (@"C:\Users\Nirmalkumar\Desktop\speech1.wav");

waveFile1 = new WaveFileWriter(tempFile1, waveSource1.WaveFormat);

waveSource.StartRecording();

waveSource1.StartRecording();

Console.Beep();

int milliseconds = 5000;

Thread.Sleep(milliseconds);


waveSource.StopRecording();

waveSource1.StopRecording();

这是第一个波源


WaveInEvent waveSource = new WaveInEvent();

    waveSource.DeviceNumber = DeviceID;

    waveSource.WaveFormat = new WaveFormat(44100, 16, 2);

    waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);

    string tempFile = (@"C:\Users\Nirmalkumar\Desktop\speech.wav");

    waveFile = new WaveFileWriter(tempFile, waveSource.WaveFormat);


static void waveSource_DataAvailable(object sender, WaveInEventArgs e)

{

    waveFile.Write(e.Buffer, 0, e.BytesRecorded);


}


查看完整回答
反对 回复 2023-08-27
  • 1 回答
  • 0 关注
  • 123 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信