B4A Library AudioRecord Library

This is an Audio Recording Library based on the Android AudioRecord object which allows capturing of sound input to a data file for further processing (maybe realtime if we're lucky).

Included in the demo program is a WAV file header routine that allows saving captured sound as an uncompressed wav file.

Please read the documentation of the AudioRecord object. It's a little more complicated that the media recorder version, but gives additional flexibility.

Please test it and hopefully we can get it to work well for us.

Added libs 1.01 - Additional constants and Capitalized

12/6/2012 Artest updated to better manage thread on closedown.

For use with V2 of B4a (more specifically the latest threading library) you'll need to add a parameter to the start thread call in artest. Line 89, Record.Start("Recording",Null) becomes Record.Start(Null,"Recording",Null)

artest 1155
 

Attachments

  • AudioRecord1.01.zip
    4.9 KB · Views: 2,853
  • artest1.02.zip
    8.2 KB · Views: 1,071
Last edited:

Sarah

Member
Licensed User
Longtime User
Thanks for the library and the examples Steve - much appreciated.
I have it all working using threading as shown in your sample, although I found that it worked better if I set an interrupt flag rather than calling Interrupt on the thread itself.

I am a newcomer to this platform and have been reading about the various options as I go and I was wondering is a service module would be better than threading? I have no idea how to go about implementing a service module, but it seems to me that it is designed to be an alternative to threading.

Regards,
Sarah
 

Gary Milne

Active Member
Licensed User
Longtime User
This is an Audio Recording Library based on the Android AudioRecord object which allows capturing of sound input to a data file for further processing (maybe realtime if we're lucky).

Included in the demo program is a WAV file header routine that allows saving captured sound as an uncompressed wav file.

Please read the documentation of the AudioRecord object. It's a little more complicated that the media recorder version, but gives additional flexibility.

Please test it and hopefully we can get it to work well for us.

Added libs 1.01 - Additional constants and Capitalized

12/6/2012 Artest updated to better manage thread on closedown.

For use with V2 of B4a (more specifically the latest threading library) you'll need to add a parameter to the start thread call in artest. Line 89, Record.Start("Recording",Null) becomes Record.Start(Null,"Recording",Null)

Hi Steve, is this library still functional? I tried the sample today with B4A 4.30 and it does not do anything on screen. If I add a Log statement in the Rec_Ended routine I get the following: Thread Rec EndedOK false Exception : Wrong number of arguments; expected 4, got 0.

I looked for an updated sample but did not find any. What am I missing?

Thx.
 

ilan

Expert
Licensed User
Longtime User
hi @stevel05

i am using your audio record lib for my new call recorder. thank you very much for this lib and i was able to use it on my galaxy s5.
few members here tried it on their Android 6 phones and the recording does not start. The AR is not able to intialize even if you change the sample rate.

Do you have any idea what i can do to make it work on android 6?

thanx, ilan :)
 

ilan

Expert
Licensed User
Longtime User

ilan

Expert
Licensed User
Longtime User
On some devices its working and on some not.

Could it be something with the saving of the wav file?

The library worked for me on my galaxsy s5 with android 5 but with android 6 i am not able to hear the other side (call recording). But galaxsy s6 is working also with android 6.

Do you have an idea what it could be?
 

stevel05

Expert
Licensed User
Longtime User
What source are you using to record the call?
 

ilan

Expert
Licensed User
Longtime User
This is a good question.

The audio source for call recording is 4 but on android 6 it didnot worked after lot of test it turned out that on android 6 the microfon source will perform a call recording (both sides) so setting the source to 1 will record both sides on a call (only on android 6+)

So on my app i check for the android version and if its 6+ i set the source to 1, on android <6 i set the source to 4.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
I think your problem lies with the vendors implementation of the audio source and/or permissions. I know that call recording was never encourages (and even actively discouraged) by Google. They have changed the sources and permissions in the past to try to stop this being possible.

I have a feeling that the reason it works on some devices is that the source or permissions have not been implemented to Googles specifications by those vendors. I know that I tried it to answer a question on the forum a few years ago and the Mic didn't record both sides of the conversation. If it's working on some but not others. this seems the most likely scenario. I don't think there is anything that can be done within the library to change it.

What is your targetSDK version for the app? Does it work as it used to if it's set to < 23?

On 23+ It may be worth trying VOICE_CALL (4) and requesting the permission. It may work on some devices if it's not implemented correctly, but I don't think you will get a 100% solution because Google doesn't want it to work.
 

ilan

Expert
Licensed User
Longtime User
ok i tried it with targetsdk 23 and ask for all permissions (dangerous permissions) and no luck.
the call is recording only on my side but not the other side.

i have tried several call recorder and most wont work with my phone (after updating to android 6) but ACR is working fine.

i wonder how they have solved the problem. but there app (ACR) works :(
 

ilan

Expert
Licensed User
Longtime User
Thanx steve i will try it.
Btw can your lib save the audio to 3gp or mp4 like in the source?

B4X:
private static final String AUDIO_RECORDER_FILE_EXT_3GP = ".3gp";
private static final String AUDIO_RECORDER_FILE_EXT_MP4 = ".mp4";
private static final String AUDIO_RECORDER_FOLDER = "AudioRecorder";
 

stevel05

Expert
Licensed User
Longtime User
No, that example is based on Mediarecorder, which is available as part of the AudioRecordApp or Audiostreamer objects of the Audio library. You may need to use JavaObject on it to access all of the required functions.
 

ilan

Expert
Licensed User
Longtime User
Thanx steve. Good to know that it may be possible to save the file as 3gp.

I just need to figure out how to do it with the java object. :confused:
 

stevel05

Expert
Licensed User
Longtime User
I haven't tried it, but I would think that the returned buffer should be in the correct format to save directly to a file of the requested file type. So you may not need to do anything else with it.
 
Top