Android Tutorial Walkie Talkie - Audio streaming over Wifi or Bluetooth

Status
Not open for further replies.
This example implements a simple "walkie talkie".

270px-Wikipedia_images_011.jpg

(src: wikipedia)

SS-2013-06-30_16.26.21.png


Once the two devices are connected, either over Bluetooth or over the local network, you can press on the activity and talk. The audio captured from the microphone will be sent to the other device and played. Note that this is a half duplex solution, which means that audio will not be received while you send audio. This is to avoid positive feedback (which will also occur if the devices are close to each other).

Most of the code handles the connection. Streaming the audio is done with AudioStreamer object which was introduced in Audio library v1.5.

Note that if you are only interested in audio recording then you should follow the two examples in the above link.

The "interesting" code that is responsible for capturing the audio and sending it is quite simple:
B4X:
Sub AudioStream_RecordBuffer (Data() As Byte)
   If sendingAudio Then
      astream.Write(Data)
   End If
End Sub
Then in the other side:
B4X:
Sub astream_NewData (Buffer() As Byte)
   If sendingAudio = False Then
      'play the received audio data
      audioStream.Write(Buffer)
   End If
End Sub
 

Attachments

  • Walkie-Talkie.zip
    10.7 KB · Views: 10,048

Rick Harris

Well-Known Member
Licensed User
Is there a way to automatically pair both devices via WiFi? This question applies both to the walkie talkie and the Filetranser library.
Having to set IP numbers nearly every time is cumbersome. Automatic linking is already possible between a PC and an Android (using a local server on the PC and handshaking via a PSP script on a website), as described in another thread.
 

Avansys

Member
Licensed User
Hi Erel,

How many devices can be connected via wifi at the same time?

Is it possible?

Thanks
 

Avansys

Member
Licensed User
Many devices can be connected via wifi. This example only supports a single connection. However you can modify it to support multiple connections.

However all the data will need to go through the "server" device.
Can you help me please¡?
 

Rick Harris

Well-Known Member
Licensed User
The connection step is not really related to this example. Any method that enables you to find the other device ip address will work with this example as it will work in all other cases.
I realize that automatic Wifi connection could also apply to other situations than the Walkie Talkie.
To which methods are you referring? Kindly provide guidance how to automatically find other WiFi devices in one's own home network and to automatically connect to them.
 

Erel

Administrator
Staff member
Licensed User
Can you help me please¡?
I'm sorry but I cannot write such a solution for you. Maybe this B4J example will help you: http://www.basic4ppc.com/android/forum/threads/b4j-cctv-example.34695/#post-203347

It allows multiple devices to be connected to the same server.

I realize that automatic Wifi connection could also apply to other situations than the Walkie Talkie.
To which methods are you referring?
You can send a broadcast UDP message to all connected device and then reply with the device IP address. For further related questions please start a new thread.
 

macguiwer

Member
Licensed User
Hello Erel.
I tried using your code on a 3G connection.
this is the only modification I made
B4X:
Sub pe_ConnectivityChanged (NetworkType As String, State As String, Intent As Intent)
'    MyIP = server.GetMyWifiIP 'only for wifi
    MyIP = server.GetMyIP 'for  3G y wifi.

    UpdateUI
End Sub
but can not get it to work

Error:
(SocketTimeroutExcention) java.net.SockelTimeExcention:fault to connect to


any idea?

PD: I think the application is good.
I think the problem is that the 3G connection is behind a proxy server.

PD2 :works perfectly
the problem was that after a trip outside my country.
my internet settings was going through a Proxy.
 
Last edited:

alan dodd

Member
Licensed User
Hello, Philip.
I read your post about code you have for sending audio from android to pc.
Could you be so kind to send it to me?
I already use lakeofsoft with delphi between two pcs and it works, your code could help me get things working with android <-> windows.

Thank you.
Alan
 

vangogh

Member
Licensed User
Can I send the voice message (half duplex is OK) to ALL devices connected?

many devices connected toghether so a single "COME HERE" can be heard from anyone?

thank you
 

lemonisdead

Well-Known Member
Licensed User
Can I send the voice message (half duplex is OK) to ALL devices connected?
Hello,
Using UDP could let you do Multicast. You'll have to send the message to the IP 192.x.x.255 so all the UDP receivers could get the same message.
 
Last edited:

vangogh

Member
Licensed User
I analyzed the code but I cannot understand how to select the protocol tcp/udp...

can you help me?

I simply have to send a message like "come here" to all devices

everybody should be able to send a message that is received from anybody...

thank you
 

vangogh

Member
Licensed User
a multicast chat found in the market uses RTP - Real-time Transport Protocol - that is based on UDP
have you any suggestion or hints about how to use it the the walkietalkie app?
I still haven't found a solution I can develope *easily* ;-)
 
Status
Not open for further replies.
Top