gpt4 book ai didi

c# - 使用NAudio C#减少映射扬声器和麦克风音量的延迟

转载 作者:行者123 更新时间:2023-12-03 01:51:17 26 4
gpt4 key购买 nike

您好,我正在尝试将系统麦克风音频映射到外部声卡扬声器,并将外部声音卡麦克风音频映射到系统扬声器。通过使用代码

 public void MapForManualCall()
{
try
{
if (db.getResultOnQuery("SELECT [Value] FROM [dbo].[SystemProperties] where property='RecordingEnabled'").Rows[0][0].ToString().Equals("YES"))
{
SystemMic = new NAudio.Wave.WaveInEvent();
SystemMic.DeviceNumber = 0;
SystemMic.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(SystemMic.DeviceNumber).Channels);

SoundcardMic = new NAudio.Wave.WaveInEvent();
SoundcardMic.DeviceNumber = 1;
SoundcardMic.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(SoundcardMic.DeviceNumber).Channels);

//NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

// used to set listen property of mic on

var waveOutReceiver = new NAudio.Wave.WaveOut();
waveOutReceiver.DeviceNumber = 0;
// used to wavout caller voice on receiver speaker
NAudio.Wave.WaveInProvider waveInProviderCaller = new NAudio.Wave.WaveInProvider(SystemMic);
waveOutReceiver.Init(waveInProviderCaller);
waveOutReceiver.Play();

var waveOutCaller = new NAudio.Wave.WaveOut();
waveOutCaller.DeviceNumber = 1;
// used to wavout receiver voice on caller speaker
NAudio.Wave.WaveInProvider waveInProviderReceiver = new NAudio.Wave.WaveInProvider(SoundcardMic);
waveOutCaller.Init(waveInProviderReceiver);
waveOutCaller.Play();


//sourceStream.StartRecording();
//waveOut.Play();


// SoundcardMic.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(waveIn_DataAvailable1);
// writer1 = new NAudio.Wave.WaveFileWriter(outputFilenameReceiver, SoundcardMic.WaveFormat);
SoundcardMic.StartRecording();

//SystemMic.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(waveIn_DataAvailable);
//writer = new NAudio.Wave.WaveFileWriter(outputFilenameCaller, SystemMic.WaveFormat);
SystemMic.StartRecording();
// MapSpeakerNMic();
}
}
catch (Exception ex)
{
MessageBox.Show("Please Check Headphone and Device Cable Connected Properly!");
}
}

上面的代码很完美,但是映射之间有3-4秒的延迟。当我尝试使用Windows 7的Listen功能进行上述任务时,它的工作原理非常完美。对我来说,这可能是读写缓冲区的问题。不知道该怎么做...

最佳答案

延迟是这里的问题。在录制和播放阶段存在延迟。您会发现,不使用ASIO之类的方法很难将其减小到较小的值。但是,所有NAudio API都允许您指定缓冲区大小,这样您就可以了解在退出之前可以走多低。

关于c# - 使用NAudio C#减少映射扬声器和麦克风音量的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39451983/

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