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: 11,174

Philip Prins

Active Member
Licensed User
Longtime User
Hello Erel,

The microphone on my tablet will not work.(Asus EEpad Transformer)

another problem when i receive a phone call the microphone will not work anymore after the call , not on any application including sound recorder until i reboot my phone.
This does not occur with every call but often.

Regards,
Philip
 

Buks

Member
Licensed User
Longtime User
I get an error when compiling:
Parsing code. 0.02
Compiling code. 0.02
Compiling layouts code. 0.00
Generating R file. 0.08
Compiling generated Java code. 0.55
Convert byte code - optimized dex. Error
A referenced library is missing: jxl
 
Hello.. i was wondering... why i get this error when i try to compile this ?
Parsing code. 0.01
Compiling code. Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 120
audioStream.StartAudioStream


It is because i have Audio 1.31?
 

Jim Pritchett

New Member
I Try and run this example and i get the following error. Any Suggestions?
*** Remote compilation mode ***
Parsing code. 0.01
Compiling code. 0.03
Compiling layouts code. 0.00
Sending data to remote compiler. Error
step: Compiling generated Java code.
javac 1.7.0_09
src\b4a\example\walkietalkie\connector.java:98: error: cannot find symbol
public static anywheresoftware.b4a.audio.AudioStreamer _audiostream = null;
^
symbol: class AudioStreamer
location: package anywheresoftware.b4a.audio
Note: src\b4a\example\walkietalkie\connector.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
 

Jim Pritchett

New Member
Seems like you are still referencing the Jar file of the previous audio library. Make sure to copy Audio.xml and Audio.Jar to the internal libraries folder.
I Have copied over the two files to the C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries folder but get the same error.
 

Jim Pritchett

New Member
Seems like you are still referencing the Jar file of the previous audio library. Make sure to copy Audio.xml and Audio.Jar to the internal libraries folder.
I was able to get it to run when I deselected "Remote Compilation Mode" not sure why but it did work after doing this.
 

blooddiamond

Member
Licensed User
Longtime User
Is it possible in the same way to stream video from back camera using local network ?
 
Last edited:

Nizze

Active Member
Licensed User
Longtime User
Hi Erel
Is there a way to use the "home" button on my Samsung S4 as ptt button ??
Is it possible to "override" the normal function of this button ??



// Nizze
 

kris_audi

Member
Licensed User
Longtime User
Hi

I get the following error as soon as the application starts.


How can I remove this error? Please for more details.

--------- beginning of /dev/log/system
java.net.SocketException: Connection timed out
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:b4a.example.walkietalkie
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (connector) Create **
connector_service_create (B4A line: 36)
audioStream.Initialize("AudioStream", 22050, True, 16, audioStream.VOLUME_MUSIC)
java.lang.NegativeArraySizeException
at anywheresoftware.b4a.audio.AudioStreamer.Initialize(AudioStreamer.java:69)
at b4a.example.walkietalkie.connector._service_create(connector.java:521)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at b4a.example.walkietalkie.connector.onCreate(connector.java:42)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1949)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3689)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Unable to create service b4a.example.walkietalkie.connector: java.lang.RuntimeException: java.lang.NegativeArraySizeException
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1959)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3689)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.NegativeArraySizeException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:195)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at b4a.example.walkietalkie.connector.onCreate(connector.java:42)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1949)
... 10 more
Caused by: java.lang.NegativeArraySizeException
at anywheresoftware.b4a.audio.AudioStreamer.Initialize(AudioStreamer.java:69)
at b4a.example.walkietalkie.connector._service_create(connector.java:521)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
... 13 more
 
Status
Not open for further replies.
Top