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

mauro56

New Member
Licensed User
Longtime User
Hi,
after updating my Nexus 7 to Android 4.4.2 now I have an error and the application Walkie Talkie crashes unexpectedly. The problem seems to be in the service module "Connector". More precisely, in the subroutine:

Public Sub StopSendingAudio
audioStream.StopRecording
sendingAudio = False
end Sub

It seems to be the audiostream.StopRecording that causes abnormal termination.
With the previous version (Android 4.4.3) Walkie Talkie application works correctly.
 

mauro56

New Member
Licensed User
Longtime User
Yes, I have the same problem with the example you indicated, although less frequently. I am enclosing a few lines of the log when the error hoping you find it useful.
I correct a mistake in my previous post. The previous version of Android is 4.3.0. With this version everything is ok.

** Service (service1) Destroy **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.audiostreamerex
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NegativeArraySizeException: -3
at anywheresoftware.b4a.audio.AudioStreamer$Recorder.run(AudioStreamer.java:145)
at java.lang.Thread.run(Thread.java:841)
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
Installing file.
PackageAdded: package:b4a.audiostreamerex
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NegativeArraySizeException: -3
at anywheresoftware.b4a.audio.AudioStreamer$Recorder.run(AudioStreamer.java:145)
at java.lang.Thread.run(Thread.java:841)
** Activity (main) Pause, UserClosed = true **

Thank you for your attention.
 

mauro56

New Member
Licensed User
Longtime User
Yes, when you start the recording. And 'less frequent if you remain silent. If you register for a few seconds and close the recording application crashes. In the example of Walkie Talkies is definitely more common, but even in this final example at least once in two the application crashes. Always close when recording.
 

wm.chatman

Well-Known Member
Licensed User
Longtime User
Can't compile the Walkie Talkie Sample.

Compiling code. Error
Error parsing program.
Error description: Unknown type: audiostreamer
Are you missing a library reference?
Occurred on line: 18
Private audioStream As AudioStreamer

Audio 1.3 is avail.

what's up, any thoughts on this one ?
 

ericvanderhoeven

Member
Licensed User
Longtime User
This example implements a simple "walkie talkie".

This app works fine here on 2 tablets both fitted with Wifi AND Bluetooth. It does not seem to work on 2 tablets with wifi only.
Could that be the reason (that it does not have bluetooth)?
And if so, what lines to take out of the sample code?
On the wifi only tablets, it spits out quite a nasty (and lengthy) error log when I try to run it. On the combo tablets, no error log at all.

Any help is appreciated.

Thx,

Eric
 
Status
Not open for further replies.
Top