Speech Recognition "SrgoneOf" Automation in Visual Basic 2010

Lokesh R 61 Reputation points

I have been working on Speech Recognition in visual basic 2010 it works well. I write the "sentences to be recognized inside the "srgoneof" attribute as shown below. But It is limited and recognizes only what is written in this attribute. Can I change it to some sort of document or combobox that can be updated or added on the run time.

here is the code


        End Sub`
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,627 questions
{count} votes

Accepted answer
  1. Xingyu Zhao-MSFT 5,356 Reputation points

    Hi @Lokesh R ,
    Basically, you can define a xml file like:

    <?xml version="1.0" encoding="UTF-8"?>  
        <item>open settings</item>  
        <item>what is your favorite movie</item>  
        <item>can you give me some water</item>  
        <item>what foods do we have</item>  
        <item>get me a pepsi</item>  

    Then create a method.

        Private Function GetGrammar(id As String, xmlFilePath As String) As System.Speech.Recognition.Grammar  
            Dim AIGrammar As New Recognition.SrgsGrammar.SrgsDocument  
            Dim AiWordsRule As New Recognition.SrgsGrammar.SrgsRule(id)  
            Dim xml = XDocument.Load(xmlFilePath)  
            Dim result As String() = xml.Descendants("item").Select(Function(x) CStr(x)).ToArray()  
            Dim AIWords As New Recognition.SrgsGrammar.SrgsOneOf(result)  
            AIGrammar.Root = AiWordsRule  
            Return New Recognition.Grammar(AIGrammar)  
        End Function  

    Every time you need to load Grammar.

    recognizer.LoadGrammar(GetGrammar("words", "your xml file path"))  

    And if you want to change "SrgoneOf" at runtime, you can change 'item' elements in the xml file, and reload the Grammar.
    The code looks like:


    Hope it could be helpful.

    Best Regards,
    Xingyu Zhao
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful