如何使用 NAUDIO 进行 VoIP [英] How to VoIP using NAUDIO

查看:68
本文介绍了如何使用 NAUDIO 进行 VoIP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NAUDIO 和套接字开发 voip 服务器-客户端应用程序.

I'm developing a voip server-client app using NAUDIO and Sockets.

我已经阅读了 naudio 的文档,我尝试了很多从麦克风获取数据然后将其发送到客户端,您可以获取数据,但是您必须先将其保存到字节数组中发送它就像使用 TCP 发送文件一样.

I've read the naudio's documentation and I have tried alot to get the data from the microphone then send it to the client, the thing that you can get the data, but you have to save it to a byte array first then send it which is almost like sending a file using TCP.

如何从 naudio 获取数据并同时使用 UDP 协议将其流式传输"到客户端.

How can I get data from naudio and send it at the same time "Stream it" to the client using UDP protocol.

提前致谢.

推荐答案

如果您下载源代码,NAudio 在示例中提供了一个网络聊天演示,它很好地展示了如何实现一个非常简单的聊天应用程序.

NAudio has a Network Chat Demo within the Examples if you download the source code, which does a good job of showing how to implement a very simple Chat application.

基本上,尽管您希望客户做的是:

Basically though what you want the client to do is this:

void Initialize() 
{
    waveIn = new WaveIn();
    waveIn.BufferMilliseconds = 50;
    waveIn.DeviceNumber = inputDeviceNumber;
    waveIn.WaveFormat = codec.RecordFormat;
    waveIn.DataAvailable += waveIn_DataAvailable;
    waveIn.StartRecording();
    ...
}

void waveIn_DataAvailable(object sender, WaveInEventArgs e)
{
   //Encode and send e.Buffer
}

有了这个,您每 50 毫秒(或您设置的缓冲区长度)获得一个字节数组并将其发送到服务器.但是,您需要对其进行编码,因为发送未编码的声音会占用太多带宽.NAudio 有自己的编解码器,所以这应该不是什么大问题.请参阅此处了解 NAudio 的网络聊天演示.

With this you get a byte array every 50 ms (or however long you set you buffer to) and send it to the server. You'll need to encode it however, since sending the sound un-encoded will take up too much bandwidth. NAudio has codecs of its own, so that shouldn't be much of a problem. See here for NAudio's network chat demo.

要考虑的另一件事是,如果您计划实现客户端到客户端的 voip(通过 p2p 或通过服务器本身流式传输)是一个很好的网络库,可以处理所有通信.我在一个类似的项目中使用了 Lidgren,效果很好.它是开源的,但可以轻松设置以满足您的需求.

Another thing to consider, if you plan to implement a client to client voip (either via p2p or streamed through the server itself) is a good networking library to handle all the communications. I've used Lidgren on a similar project which worked pretty well. It's open source, but can easily be set up to fit your needs.

这篇关于如何使用 NAUDIO 进行 VoIP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆