1. Download the free trial version

Tutorial Voice Recognition Example

Discussion in 'Tutorials & Examples' started by Jamie, Mar 2, 2011.

  1. Jamie

    Jamie Member Licensed User

    Here's a quick example of voice recognition.
    It just displays the results to the log window.
    This example shows all the different recognized patterns that are returned by the Voice Module, usually 4 or 5 possibilities.

    Code:
    'Activity module
    Sub Process_Globals
       
    'These global variables will be declared once when the application starts.
       'These variables can be accessed from all modules.
    Dim VR As VoiceRecognition

    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.

    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    VR.Initialize(
    "VR")
    VR.Listen

    End Sub
    Sub VR_Result (Success As Boolean, Texts As List)
       
    If Success = True Then
       
    For i = 0 To Texts.Size -1
       
    Log (Texts.Get(i))
       
    Next
       
    End If   
       
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub
    Last edited: Mar 2, 2011
  2. mcmanu

    mcmanu Active Member Licensed User

    Hi

    Where i can find the Phone Library?
    and how to use it so that i can use Voicerecognition? sorry because of my english ;)
  3. klaus

    klaus Expert Licensed User

    The phone library is part of Basic4Android.
    When you run the IDE, you have in the lower right corner a tab called Lib.
    There you should see the Phone library, check it and it should work.
    The latest version of the library is 1.6

    Best regards.
  4. mcmanu

    mcmanu Active Member Licensed User

    hi

    Oh okay thanks ;) iam blind xD
    A i love basic4android its so simple to use ;)
  5. mcmanu

    mcmanu Active Member Licensed User

    Another Question ;)

    I have another question, i have now Programmed that the voicereg. Listens to me when i click a button. Now i want it to write what i was saying into the edittext, how can i do that?
  6. klaus

    klaus Expert Licensed User

    Did you have a look at this Voice recognition example ?
    And change the code:
    Code:
    Sub VR_Result (Success As Boolean, Texts As List)
        
    If Success = True Then
            EditText1.Text = Texts.Get(
    0)
        
    End If
    End Sub
    Best regards.
  7. mcmanu

    mcmanu Active Member Licensed User

    Thanks

    Oh okay so easy Thanks ;)
    yes i have recognized that in the forum are a lots of examples ;)
    Thanks a lot ;)
  8. klaus

    klaus Expert Licensed User

    I didn't know the answer either, but I typed 'voice recognition' in the search field just below the Basic4Android logo and found the example.

    Best regards.
  9. mcmanu

    mcmanu Active Member Licensed User

    thanks

    Yes, now i know it and search for it
    Thank you ;)
  10. Askjerry

    Askjerry Member Licensed User

    :sign0098:

    I was hoping to be able to do something with voice recognition... I simply cannot believe how easy it was! AWESOME. Here is my code... you click a button and it drops it into a label.

    Why a label? Because I didn't want the user to edit it... just display it... and it works very nicely!!!

    Code:
    Sub Button1_Click
    Dim VR As VoiceRecognition
       VR.Initialize(
    "VR")
       VR.Language=
    "en"
       VR.Prompt=
    "Talk to me!"
       VR.Listen
       
    ' If it workes it will jump to VR_Result
    End Sub

    Sub VR_Result (Success As Boolean, Texts As List)
        
    If Success = True Then
            Label1.Text = Texts.Get(
    0)
        
    End If
    End Sub
    I originally had the DIM in the initial setup... but then it didn't work... so I moved it to the button click area... then it was happy.

    Anyway... thanks again!
    Jerry
    Last edited: Jan 26, 2013
  11. marcocim

    marcocim Member Licensed User

    B4A-HelpViewer crash

    My B4A-HelpViewer.exe crashes on startup with an 'OfflineHelper stops to run'.

    Thanks

    Marco
  12. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this issue.
  13. skywalker34

    skywalker34 Member Licensed User

    Hi Erel,

    I have done some good job from all example, thanks to you and all that share their knowledge

    In a project I want to use interectiv with TTS and voice recognition

    If I play a message using TTS I have to wait certain time before using VR.listen else the VR get my TTS sentence.

    So I coded something like
    TTS1.speak (my_sentence,true)
    do while timer_delay<2000
    doevents
    loop
    VR.listen

    1/ Is there a way to know where then TTS.speak has finished it job better than having a loop with delay, because this needed delay varie depending on the sentence to pronounce as the voice synthesizer parameters ?

    2/ Where can I found the differents events definition corresponding to TTS (or other)like the TTS_ready (success as boolean) ?

    Rgds

    Sky
  14. Erel

    Erel Administrator Staff Member Licensed User

    2) You can see the events in the documentation: Basic4android - TTS

    Or better in the IDE. See the IDE tips tutorial (there is a link in my signature).

    1) TTS service sends an intent when it finishes. You can use PhoneEvents to handle the TextToSpeechFinish event.
  15. skywalker34

    skywalker34 Member Licensed User

    thanks for those info, I am still beginner in B4A :( , could you please detail and give sample code on the way to handle this phoneEvents ?

    Rgds

    Sky
  16. skywalker34

    skywalker34 Member Licensed User

    As I made lots of exchange with the user I wrote a sub with

    TTS1.speak (my_sentence,true)
    do while timer_delay<2000
    doevents
    loop
    VR.listen

    that I can call each time I need to ask something and get answer
    The problem is that after several exchange with the user the TTS.speak don't speek anymore :confused:

    Any idea of what happen ?
  17. Erel

    Erel Administrator Staff Member Licensed User

    You should create an object of type PhoneEvents (from the Phone library) and handle the TextToSpeechFinish event.

Share This Page

Loading...