LokeshRawat-9045 avatar image
0 Votes"
LokeshRawat-9045 asked LokeshRawat-9045 edited

Speech Recognition "SrgoneOf" Automation in Visual Basic 2010

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`

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have created the grammar via "srgGrammer" with "srgdocument" and then I am adding a word rule that gets the "srgoneof" from the the written array of sentences .

Th things that you have referred is not going to add the swords at runtime or from any editable controlbox like combobox an other stuff. Ans is also a bit more confusing ..I was hopping if someone could explain it with an example and teach me to automate in a hands on manual mode

0 Votes 0 ·

Because I am basically looking to replace this "Srgoneof" to something like ..a text file from where I can get or save more commands as well as a new way to get the recognnizer audio / sentences to be able to add at run time

0 Votes 0 ·

1 Answer

XingyuZhao-MSFT avatar image
0 Votes"
XingyuZhao-MSFT answered LokeshRawat-9045 edited

Hi @LokeshRawat-9045 ,
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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thank you @XingyuZhao-MSFT . It works perfeclty fine.

But I have another issue that I am getting an error while updating the XML file from vb "Data at Root Level is invalid Line1 Position 1 "

belwo is my code to add another statements into XML file.


0 Votes 0 ·