Android Code Snippet Voice Recognition with Resumable Subs

The ability of resumable subs to return values (added in B4A v7.3) makes it very simple to add voice recognition to your app.

Code:
B4X:
Private Sub RecognizeVoice As ResumableSub
   vr.Listen
   Wait For vr_Result (Success As Boolean, Texts As List)
   If Success And Texts.Size > 0 Then
     Return Texts.Get(0)
   End If
   Return ""
End Sub

You can call it like this:
B4X:
Wait For (RecognizeVoice) Complete (Result As String)

Example:
B4X:
Sub Activity_Click
   Wait For (RecognizeVoice) Complete (Result As String)
   If Result <> "" Then
     Activity.Title = Result
   End If
End Sub

Example is attached.
 

Attachments

  • vr.zip
    6.7 KB · Views: 3,943

jimmyF

Active Member
Licensed User
Longtime User
Thank you! This is excellent and just what I was looking for. :)
 

rtek1000

Active Member
Licensed User
Longtime User
When it fails to recognize the voice, it prompts the user to try again by clicking on the button in the dialog.

How to abort it?
 

Beja

Expert
Licensed User
Longtime User
When starting new question as advised by Erel, I suggest that people leave a link to the new thread so it can easily be found and followed.
 

DonManfred

Expert
Licensed User
Longtime User

ykucuk

Well-Known Member
Licensed User
Longtime User
hi,
it doesn't work with a tablet with android 8.1

Error
B4X:
onActivityResult: wi is null
 

ykucuk

Well-Known Member
Licensed User
Longtime User
Are you running the example as-is? What do you see when you click on the activity?
i used an example project. Nothing happened. Any of dialogs cant appear. I checked log the error is
B4X:
onActivityResult: wi is null
 

Beja

Expert
Licensed User
Longtime User
The ability of resumable subs to return values (added in B4A v7.3) makes it very simple to add voice recognition to your app.

Code:
B4X:
Private Sub RecognizeVoice As ResumableSub
   vr.Listen
   Wait For vr_Result (Success As Boolean, Texts As List)
   If Success And Texts.Size > 0 Then
     Return Texts.Get(0)
   End If
   Return ""
End Sub

You can call it like this:
B4X:
Wait For (RecognizeVoice) Complete (Result As String)

Example:
B4X:
Sub Activity_Click
   Wait For (RecognizeVoice) Complete (Result As String)
   If Result <> "" Then
     Activity.Title = Result
   End If
End Sub

Example is attached.

Hi Erel,
Is it possible that I can use a language for recognition other than English?

Thank you. -B
 
Top