Hi,
The B4A forum has been my main learning point when it comes to building apps and I've learn't a lot!
I'm hoping this too will help others.
I wanted to try and use a external microphone for speech recognize with my app I can easily get the sound to work but getting the mic too work I don't seem to be able to find a starting point I understand that it comes from the Java object but the piece of code i found here don't supply any log output so i can't even try and workout.
Any pointers would really be helpful.
The B4A forum has been my main learning point when it comes to building apps and I've learn't a lot!
I'm hoping this too will help others.
I wanted to try and use a external microphone for speech recognize with my app I can easily get the sound to work but getting the mic too work I don't seem to be able to find a starting point I understand that it comes from the Java object but the piece of code i found here don't supply any log output so i can't even try and workout.
Any pointers would really be helpful.
B4X:
Sub Process_Globals
Dim Voice As VoiceRecognition
End Sub
Sub Globals
Dim profile As JavaObject
Dim RecognitionDone As Boolean = False
End Sub
Sub Activity_Create(FirstTime As Boolean)
Voice.Initialize("Voice")
CallSub(Me, "GetProfileProxy")
End Sub
Sub GetProfileProxy
Dim adapter As JavaObject = BluetoothAdapter
Dim listener As Object = adapter.CreateEvent("android.bluetooth.BluetoothProfile.ServiceListener", _
"profile", Null)
Log("Success: " & adapter.RunMethod("getProfileProxy", Array(GetContext, listener, 1)))'1 = headset
End Sub
Sub Profile_Event (MethodName As String, Args() As Object) As Object
Log(MethodName)
'If MethodName = "onServiceConnected" Then
Dim profile As JavaObject = Args(1)
Log(profile)
'End If
Return Null
End Sub
Sub BluetoothAdapter As JavaObject
Dim adapter As JavaObject
adapter = adapter.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethod("getDefaultAdapter", Null)
Return adapter
End Sub
Sub GetContext As JavaObject
Return GetBA.GetField("context")
End Sub
Sub GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetFieldJO("processBA")
End Sub
Sub Voice_Result(Success As Boolean, Text As List)
If (Success) Then
Dim Lines As String = ""
For i = 0 To Text.Size - 1
Lines = Lines & "|>" & Text.Get(i)
Next
Log(Lines)
End If
RecognitionDone = False ' keep going
End Sub
Sub Activity_Resume
If (RecognitionDone) Then
RecognitionDone = False
Else
Voice.Listen
End If
End Sub
Sub Activity_Pause(UserClosed As Boolean)
End Sub