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: 3,025
  • artest1.02.zip
    8.2 KB · Views: 1,223
Last edited:

ilan

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.

Sorry i dont understand. The returned buffer is a wav file or am i wrong?
 

stevel05

Expert
Licensed User
Longtime User
In the AudioRecord library it is an array of PCM samples to which a wave header can be attached to make it a Wav file. In the MediaRecorder (AudioRecordApp or Audiostreamer) as you can specify an encoding type, it would make sense that the returned data buffer is in the format of the encoding you specified. I'm afraid you'll have to try it to see, but I would be surprised if it doesn't work like that.
 

rtek1000

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,

Example 'artest.zip' no works here:

B4A version: 6.31
Parsing code. (0.04s)
Compiling code. Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 95
Record.Start("Recording",Null)
Word: )


Dim Record As Thread

Thread has a new usage?
 
Last edited:

rtek1000

Active Member
Licensed User
Longtime User
Hi,

Example 'artest.zip' no works here:

B4A version: 6.31
Parsing code. (0.04s)
Compiling code. Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 95
Record.Start("Recording",Null)
Word: )

Thread has a new usage?

Hi, I changed this code Record.Start("Recording",Null) to Record.Start(Null,"Recording",Null), and returns:
** Activity (main) Create, isFirst = true **
Pos 40
main_activity_create (java line: 391)
java.lang.RuntimeException: Thread.Start : Sub recording not found!
at anywheresoftware.b4a.agraham.threading.Threading.Start(Threading.java:207)
at com.stevel05.artest.main._activity_create(main.java:391)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at com.stevel05.artest.main.afterFirstLayout(main.java:102)
at com.stevel05.artest.main.access$000(main.java:17)
at com.stevel05.artest.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
java.lang.RuntimeException: Thread.Start : Sub recording not found!
 

stevel05

Expert
Licensed User
Longtime User
The first parameter should be 'me' so it calls the sub in the current module. There are other errors, probably needs updating for newer OS's. I'll try to take a look this evening.
 

stevel05

Expert
Licensed User
Longtime User
Artest1.02 is working as expected. It won't work in debug mode as it's not possible to run threads in debug mode.
 
Top