B4A Library Voice (recording) Visualizer

It (partly) wraps this Github project. Don't let the name fool you - it is a visualizer driven by input from the device's microphone.

Posting:
1. B4A libraries
2. The Java source code - change it to your liking
3. B4A project demonstrating it.

1.png


Sample Code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aVoiceRecordingVisualizer
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private vrv1 As VisualizerView
    Private b1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    vrv1.Color = Colors.ARGB(100, 0, 0, 150)
    vrv1.Visible = True
    vrv1.NumberOfColumns = 100
    vrv1.RenderColor = Colors.red
    vrv1.RenderType = 1                'can oly be 1 = bar or 2 = pixel


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   
    vrv1.releaseRecorder

End Sub


Sub b1_Click
   
    vrv1.toggleRecording
   
End Sub

VoiceRecordingVisualizer
Author:
Github: Takayuki Yorikane, Wrapped by: Johan Schoeman
Version: 1

  • Fields:
    • visualizerView As Int[]
    • visualizerView_numColumns As Int
    • visualizerView_renderColor As Int
    • visualizerView_renderRange As Int
    • visualizerView_renderType As Int
  • VisualizerView
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • addListener2
    • onCalculateVolume (volume As Int)
    • releaseRecorder
    • toggleRecording
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • NumberOfColumns As Int [write only]
      Set the number of columns for the visualizer
    • RenderColor As Int [write only]
      Set the render color of the visualizer
    • RenderType As Int [write only]
      Set the render type
      1 = Bar Graph
      2 = Pixel
      It will default to Bar if an invalid value is passed
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • VoiceRecordingVisualizerLibFiles.zip
    12.3 KB · Views: 517
  • b4aVoiceRecordingVisualizer.zip
    9.5 KB · Views: 517
  • TheJavaCode.zip
    24 KB · Views: 444

Daniel-White

Active Member
Licensed User
Longtime User
Hi Johan, I did a test, only in my LG phone, I noticed it is very sensitive, the bars dance a lot.
perhaps, I guess, if some one will use or need this great lib, can add some volumen control or input threshold to Microphone in the code in B4A. I guess it can be done and allow the end user to adjust it. :)
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan, I did a test, only in my LG phone, I noticed it is very sensitive, the bars dance a lot.
perhaps, I guess, if some one will use or need this great lib, can add some volumen control or input threshold to Microphone in the code in B4A. I guess it can be done and allow the end user to adjust it. :)
Will have to go check the original Github code to see where we can add a throttle...
 

Johan Schoeman

Expert
Licensed User
Longtime User
Requested by @gerredtor - ability to request the dB value from the library. Posting new lib files and sample B4A project.

Sample Code
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aVoiceRecordingVisualizer
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
    Dim t As Timer

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private vrv1 As VisualizerView
    Private b1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
   
    t.Initialize("t", 200)
   
    vrv1.Color = Colors.ARGB(100, 0, 0, 150)
    vrv1.Visible = True
    vrv1.NumberOfColumns = 100
    vrv1.RenderColor = Colors.red
    vrv1.RenderType = 1                'can oly be 1 = bar or 2 = pixel


End Sub

Sub Activity_Resume
   
    t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   
    t.Enabled = False
    vrv1.releaseRecorder
   

End Sub


Sub b1_Click
   
    vrv1.toggleRecording
   
End Sub

Sub t_tick
   
    Dim myval As Int  = vrv1.DecibelValue
    Log("Decibel value = " & myval)
   
End Sub
 

Attachments

  • VoiceRecordingVisualizerLibFiles_V1.01.zip
    12.4 KB · Views: 476
  • b4aVoiceRecordingVisualizer.zip
    9.6 KB · Views: 418

SJQ

Member
Licensed User
Longtime User
Hi Johan,

I know you also have the AndroidRecorder that records to a file (.wav), is it also possible to record to a file with this library?

I need to monitor the Db level and if the level goes above a specific value i have to start recording to a file for a predetermined time.

Regards
Steve
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

I know you also have the AndroidRecorder that records to a file (.wav), is it also possible to record to a file with this library?

I need to monitor the Db level and if the level goes above a specific value i have to start recording to a file for a predetermined time.

Regards
Steve
Unfortunately not. I will post the Java code and then you can amend it. Then use the other project that you have referred to for the additional code that you might require in the library.
 
  • Like
Reactions: SJQ

peacemaker

Expert
Licensed User
Longtime User
Is it possible to get some data output array of the voice pattern ? To compare sounds, recognize (not text, just sound kinds).
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hi Johan, is possible change the input from the device's microphone to Volume_Music ?
 
Top