B4A Library Audio library v1.5 - New AudioStreamer object

Status
Not open for further replies.
This version includes a new AudioStreamer type. Note that this is a beta version (for this type only).

The purpose of AudioStreamer is to make it simple to stream audio from the microphone and to the speakers. Internally it is based on AudioTrack and AudioRecord.

Next week I plan to create an example of streaming audio between two devices (walkie-talkie app).

Recording is done by calling StartRecording. The RecordBuffer event will be raised multiple times during the recording:
B4X:
Sub streamer_RecordBuffer (Buffer() As Byte)
   'collect the recording data
   buffers.Add(Buffer)
End Sub
You can write this data to a file or as done in this example, collect the buffers in a list. Later we will use this list to play the recording:
B4X:
Sub btnPlay_Click
   btnStartRecording.Enabled = False
   streamer.StartPlaying
   For Each b() As Byte In buffers
      streamer.Write(b)
   Next
   streamer.Write(Null) 'when this "message" will be processed, the player will stop.
End Sub
Note that the player has an internal queue. The write method will not block the main thread. The data is just added to the queue. It is processed by another thread.

SS-2013-06-26_17.07.34.png
 

Attachments

  • AudioStreamerExample.zip
    10.4 KB · Views: 1,233
Last edited:

freedom2000

Well-Known Member
Licensed User
Longtime User
Not too much. See the first post.

Hi again,

I tested the 1.62 library

1) the App no longer crashes when the audio stream is already booked by another app
2) however I don't know how to trap the added event ?
3) I also tested the various sources with the intialize2 method

only DEFAULT and MIC seem to work on my Nexus 5 kitkat 4.4.2
all the other options raise an exception when startrecording occurs
 

freedom2000

Well-Known Member
Licensed User
Longtime User
You can handle it with:
B4X:
Sub streamer_Error
Log(LastException)
End Sub

3) Can you post the error message?
So I logged the last exception and I got :

(IllegalStateException) java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.

the init itself does not raise an exception
 

danielt

New Member
Licensed User
Longtime User
So I logged the last exception and I got :

(IllegalStateException) java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.

the init itself does not raise an exception

Hi Erel and co. Just wondering if anyone has a solution for this? I'm also hoping to use a Bluetooth headset microphone as the input.

I get the same exception if I try to use VOICE_UPLINK (2) for example. DEFAULT and MIC work fine.
 

brelto85

Active Member
Licensed User
Longtime User
with the version 1.62, is possible to set the AudioSource to VOICE_RECOGNITION and record/handle the voice in alternative to SpeechRecognizer library?
If so, has a sense to do?
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Make sure to use the latest Audio library as it allows you to handle this error instead of crashing.

This error means that Android failed to open this channel. There isn't much that can be done about it.
I can confirm that the 1.62 version of the lib handles properly this exception

And that it is really dependant on the device you are using, some accept more audio channels than others... That's life !
 

DRSolomon

New Member
Licensed User
Longtime User
Greetings people,

Working with the videorecord aspect and all is well, however I need to be able to turn the flash of programmatically..... Anyone got a snippet for me in this regard please..... Any working example?
I'm also looking for a means to get the ambient light level from the light sensor on the phone, any ideas?

Many thanks
 
Status
Not open for further replies.
Top