VOIP服务器和客户端出错的尝试

发布于 2024-10-31 14:12:09 字数 1040 浏览 0 评论 0原文

您好,我正在创建一个 VOIP 客户端和服务器,它比我预期的要好,因为我以为我第一次尝试不会听到任何声音。但实际上,我听到自己的声音大约有一两秒钟,直到我的程序在我创建的类中抛出异常,该类是为了简化发送音频字节并实时播放它们的套接字过程而创建的。这是下面的代码:

        // 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();
        }

PS如果您需要我显示更多代码,请询问,我很乐意向您展示。

Hi I am creating a VOIP 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜夜流光相皎洁 2024-11-07 14:12:09

通常的方法是让单个 WaveOut 设备不断播放并从 BufferedWaveProvider(在最新的 NAudio 代码中可用)获取其数据,而不是不断地打开和关闭 WaveOut 设备。然后,在listener_streaming中,您只需将接收到的字节添加到BufferedWaveProvider

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文