开发者

Attempt of VOIP Server and Client Gone Wrong

开发者 https://www.devze.com 2023-02-23 04:25 出处:网络
Hi I am creating a 开发者_StackOverflowVOIP client and server, and it is going better than I expected since I was thinking that I was not going to hear nothing for my first attempt. But actually I am

Hi I am creating a 开发者_StackOverflowVOIP client and server, and it is going better than I expected since I was thinking that I was not going to hear nothing for my first attempt. But actually I am hearing myself fine for about a second or two until my program throws an exception within a class I created to simplify the socket process of sending audio bytes and playing them in real time. Here is the code below:

        // public function member of class DataArgs 
        public void PlayRealTimeAudio()
        {

                WaveOut o = new WaveOut();
                o.DeviceNumber = 0;
                o.DesiredLatency = 500;
                Stream s = new MemoryStream(this.Buffer);
                Raw.RawSourceWaveStream raw = new Raw.RawSourceWaveStream(s, new WaveFormat(16000, 2));
                o.Init(raw); // Exception throws here after hearing my voice for a brief moment
                o.Play();
                o.Stop();
                o.Dispose();

            return;
        }


        // Within the Form1 class
        void listener_Streaming(System.Net.Sockets.TcpClient sender, DataArgs e)
        {
            byte[] buf = new byte[e.Length];
            buf = e.Buffer;
            e.PlayRealTimeAudio();
        }

P.S If you need me to show more code please ask, I will be glad to show you.


rather than constantly opening and closing the WaveOut device, the normal way to do this would be to have a single WaveOut device constantly playing and getting its data from a BufferedWaveProvider (available in the latest NAudio code). Then, in listener_streaming, you would simply add the bytes received to the BufferedWaveProvider

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号