Streaming voice between Android Phones over WiFi

时光总嘲笑我的痴心妄想 提交于 2019-11-27 17:01:47

Hey there is an Open Source library called "Libstreaming" that is used for streaming voice/video over the network using WIFI. Just Have a look at it:

https://github.com/fyhertz/libstreaming

There are also some examples provided, kindly have a look at it:

https://github.com/fyhertz/libstreaming-examples

I have used the library to Stream RTSP Audio over the network,hope it may be useful.

Atul Goyal

I'd try dividing the problem into Three parts.

Part 1

Ensure the Socket Connection is working fine by commenting everything related to audio

Part 2

Send simply just an arbitrary text message [Hello WiFi] from the sender, then receiving and printing it in the receiver side application.

Part 3

Whether the recorder is actually working? try to test your recording way in separate project to see if it is working properly or not.

Use this code to capture microphone and play it.

My experience

I once worked on a similar project and to test it, what I did was after recording I wrote the recorded audio data as a file on the sdcard

(it would be raw audio, so most music players won't be able to play it... mPlayer should play it I guess)

You need to carefully consider your use of UDP (DatagramSocket class) as your network protocol.

UDP is a lightweight protocol that does not guarantee to maintain the ordering of received packets. This may be part of the reason why the audio is garbled. A packet received out of order will result in a packets worth of audio being played out of order. At the boundary of these out-of-sequence packets you will hear clicks/pops where the audio sample is effectively corrupt. In addition to this, UDP packets aren't guaranteed to be delivered successfully. Any dropped packets will obviously add to any garbling or distortion that is heard.

TCP (Socket class) would be a better option for optimum audio quality. TCP is a more robust protocol that will maintain the order that packets are received. It also has in-built error checking and will resend any dropped packets. However, because of this attentional functionality, TCP has a higher network overhead.

I started this response by saying that you need to carefully consider which protocol you use. This is because there is a case for using either depending on what is important to you..

If you want ultra low latency playback but are happy to sacrifice the audio quality then UDP will work. However, it will take some experimentation to find the best buffer and sample size.

If you want the best possible audio re-production with zero distortion but are happy to introduce slightly more latency then TCP is the route to go.

I can't say how much more latency TCP would add. But it is possible that it could be implemented without impacting the user experience. The only way to find out is to try it and see.

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