Reduce delay in mapping speaker and mic volume using naudio c#

佐手、 提交于 2019-12-12 02:36:31

问题


Hello i am trying to map system mic audio to external sound card speaker and external sound card mic audio to system speaker. By using code

 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!");
        }
    }

Code above works perfect but there is delay of 3-4 seconds between mapping. When i am trying above task using Listen functionalities of windows 7 it works perfect. According to me it can be issue of reading writing buffer. Don't know how to do it...


回答1:


Latency is the issue here. There is latency at the recording and playback stage. You will find it very hard to reduce this to small values without using something like ASIO. However, all the NAudio APIs allow you to specify buffer sizes so you can see how low you can go before you get dropouts.



来源:https://stackoverflow.com/questions/39451983/reduce-delay-in-mapping-speaker-and-mic-volume-using-naudio-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!