This example implements a simple "walkie talkie".
(src: wikipedia)
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:
Then in the other side:
(src: wikipedia)
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
B4X:
Sub astream_NewData (Buffer() As Byte)
If sendingAudio = False Then
'play the received audio data
audioStream.Write(Buffer)
End If
End Sub