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,945

ciapw

Member
Licensed User
Do you mean the same protocol is the same wifi connection? IIf i am mistaken, please kindly explained it to me. Thanks a lot for your help :)
This example works on Android. It sends or receives raw PCM data. You can build a similar solution that runs on a different client. It will work if you use the same protocol.
 

ciapw

Member
Licensed User
The data in this example is PCM data and it is sent with AsyncStreams in prefix mode.

This is the protocol.
Hi Erel. I found this post written by you. If my data will be sent through I2C from button hardware to nanopi, i couldn't use AsyncStreams in prefix mode, could I?

In order to use prefix mode you will need to have full control over the data that is sent from the serial device. It will not be possible to use prefix mode with most serial devices.
 
Last edited:

ciapw

Member
Licensed User
For all interested without prefix mode you can also send and receive audio to a PC removing prefix mode with TCPIP or by using UDP send packet and receive packet.
Off course make sure that you use the same audio settings on both sides regarding samplerate bits per second etc.

When you use UDP set the receive buffer size to the right buffer for the codec ,example 320 for PCM 8000 .

Great addition Erel....
Hi Philip .. Can we use UDP send and receive packet method by taking the data from mqtt broker? The idea will be like this :

1.Person A press the button on the phone , the phone will record the message and when person A press the button again , the message will be sent through a MQTT broker (test.mosquitto.org)
2. When a message is sent from A, NanoPi will get the message from test.mosquitto.org, NanoPi will playback the message so person B will hear it.

Thankyou . I am looking forward to your reply:)
 

cxdzbl

Active Member
Licensed User
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
How can I make the recording do not save directly to byte, and then convert byte to audio file playback?
 

Roland Obeng

New Member
Licensed User
the walkie talkie example above works perfectly.
Please I want to ask if communication can be done through radio waves(channels) between two android devices instead of WiFi and Bluetooth.

I would like an example if it is going to be possible

Thanks
 

deantangNYP

Active Member
Licensed User
Longtime User
May i know how can i configure this WalkieTalkie example to operate in Cellular Network? (assuming i know the IP address of both the Android device)
also, possible to have it in full duplex (ignoring the feedback)?
Thanks
 
Last edited:
Status
Not open for further replies.
Top