Android Code Snippet Voice Recognition with Resumable Subs

Discussion in 'Code Snippets' started by Erel, Aug 17, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed 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:
    Code:
    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:
    Code:
    Wait For (RecognizeVoice) Complete (Result As String)
    Example:
    Code:
    Sub Activity_Click
       
    Wait For (RecognizeVoice) Complete (Result As String)
       
    If Result <> "" Then
         
    Activity.Title = Result
       
    End If
    End Sub
    Example is attached.
     

    Attached Files:

    • vr.zip
      File size:
      6.7 KB
      Views:
      3,061
  2. jimmyF

    jimmyF Active Member Licensed User

    Thank you! This is excellent and just what I was looking for. :)
     
  3. rtek1000

    rtek1000 Active Member Licensed 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?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  5. Beja

    Beja Expert Licensed 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.
     
    aidymp likes this.
  6. DonManfred

    DonManfred Expert Licensed User

    Beja likes this.
  7. ykucuk

    ykucuk Well-Known Member Licensed User

    hi,
    it doesn't work with a tablet with android 8.1

    Error
    Code:
    onActivityResult: wi is null
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Are you running the example as-is? What do you see when you click on the activity?
     
  9. ykucuk

    ykucuk Well-Known Member Licensed User

    i used an example project. Nothing happened. Any of dialogs cant appear. I checked log the error is
    Code:
    onActivityResult: wi is null
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the full logs?

    Maybe the process is being killed at some point.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice