Hi @Lokesh R ,
Basically, you can define a xml file like:
<?xml version="1.0" encoding="UTF-8"?>
<message>
<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>
</message>
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)
AiWordsRule.Add(AIWords)
AIGrammar.Rules.Add(AiWordsRule)
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:
recognizer.UnloadAllGrammars()
recognizer.LoadGrammar(GetGrammar(...))
recognizer.RecognizeAsync(RecognizeMode.Multiple)
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.