通过 UDP 在 wifi 网络中传输音频
我必须实现一个小软件,在同一 WiFi 网络中的两台电脑之间发送音频流。
简而言之,我从麦克风等设备获取音频,然后我必须实时传输该音频。 也许我会使用 Java..
通过 UDP 传输数据,如下所示:
//create UDP socket
DatagramSocket socket = new DatagramSocket();
//data to be sent
byte[] buf = (data).getBytes();
//create UDP packet
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
//send the packet
socket.send(packet);
...
好吧,我的问题是,如何将音频源拆分为将存储在 buf 中的数据包?
如何在另一台电脑上接收数据包然后“重新组装”或直接播放?
这是正确的方法吗?非常感谢。你好!
I have to implement a little software that sends an audio stream between two pc in the same WiFi network..
In little words, I get audio from device like a mic and then I have to transmit this audio in real time..
maybe I'll use Java..
To transmit data trough UDP something like this:
//create UDP socket
DatagramSocket socket = new DatagramSocket();
//data to be sent
byte[] buf = (data).getBytes();
//create UDP packet
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
//send the packet
socket.send(packet);
...
Well, my question is, how can I split the audio source in packets that I'll store in buf?
how can I receive the packets in another pc and then "reassembly" or play directly?
It's the right way? Thanks very much. Hi!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不使用 TCP 而使用 UDP?使用 TCP 套接字,您可以轻松实现流功能。
如果您坚持使用 UDP,则必须实现某种数据包编号,然后重新组装,然后仅在拥有所有数据包时才播放,等等。尽量避免它。
Why don't you use TCP instead of UDP? With TCP sockets, you'll have stream functionality implemented with no extra hassle.
If you stick with UDP, you'll have to implement some kind of packet numbering, then reassembly, then play only when you have them all, and so on. Try to avoid it.