iOS Question AudioRecorder - how to managing audio-level metering

Alexander Stolte

Expert
Licensed User
Longtime User
I would like to record my voice and visualize the audio live. I use the AudioRecorder on the iMedia library for this. I read in the Apple documentation that you can activate audio metering and extract the data from it.

Unfortunately the AudioRecorder library does not support this, how can I extend the AudioRecorder with objc code?

It is about the following properties:
ismeteringenabled

updateMeters

averagePowerForChannel

Thanks :)
 
Solution
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private recorder As AudioRecorder
    Private recording As Boolean
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    recorder.Initialize(xui.DefaultFolder, "1.mp4", 44100, False, 8, True)
    recorder.As(NativeObject).SetField("meteringEnabled", True)
End Sub


Private Sub Button1_Click
    recorder.Record
    recording = True
    Dim nRecorder As NativeObject = recorder
    Do While recording
        nRecorder.RunMethod("updateMeters", Null)
        Sleep(50)
        If recording Then...

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private recorder As AudioRecorder
    Private recording As Boolean
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    recorder.Initialize(xui.DefaultFolder, "1.mp4", 44100, False, 8, True)
    recorder.As(NativeObject).SetField("meteringEnabled", True)
End Sub


Private Sub Button1_Click
    recorder.Record
    recording = True
    Dim nRecorder As NativeObject = recorder
    Do While recording
        nRecorder.RunMethod("updateMeters", Null)
        Sleep(50)
        If recording Then
            Log(nRecorder.RunMethod("averagePowerForChannel:", Array(0)).AsNumber)
        End If
    Loop
End Sub

Private Sub Button2_Click
    recording = False
    recorder.Stop    
End Sub

And don't forget to add to main module:
B4X:
 #PlistExtra:<key>NSMicrophoneUsageDescription</key><string>description here...</string>
 
Upvote 0
Solution
Top