Question Speech Recognition question

manbearpig001

Member
Joined
Jun 15, 2012
Messages
8
Programming Experience
5-10
Hey,
I have been trying to create a set of grammar rules for a speech recognition program with an array, but cannot seem to accomplish this task. Here is the general idea:

VB.NET:
Dim commandlist As New Recognition.SrgsGrammar.SrgsOneOf(websites(0), websites(1), websites(2))
        commandRule.Add(commandlist)
        gram.Rules.Add(commandRule)
        gram.Root = commandRule
        recog.LoadGrammar(New Recognition.Grammar(gram))

I have a string array - websites() - and for each string in this array, I want to add it to the commandlist. Unfortunately, the only way I know of doing this is by writing it one by one, as seen above. I tried doing this:

VB.NET:
Dim commandlist As New Recognition.SrgsGrammar.SrgsOneOf
        dim i as integer = 0
        do until i = websites.items.count
        commandlist.items.add(websites(i))
        i +=1
        loop
        commandRule.Add(commandlist)
        gram.Rules.Add(commandRule)
        gram.Root = commandRule
        recog.LoadGrammar(New Recognition.Grammar(gram))

But this did not work, because I cannot convert strings into srgsoneof... Anyone have any idea how this could be done?
 
New SrgsOneOf handles arrays so is it not as simple as .... ?


Dim commandlist As New Recognition.SrgsGrammar.SrgsOneOf(websites)
 
Yes, declare commandlist as a separate instance and then use it from there.

Dim commandlist as New SrgsOneOf(websites)
 
You don't wanna give it a try first, just in case it might work? I think you'll find that there is a considerable difference in fact!
 
Tried it. Threw an error, so I imported System.Speech.Recognition.SrgsGrammar, and it did not do anything. Perhaps I misunderstood the code you presented?
 
There is one rather important difference at least. One works, the other doesn't! The syntax is sacrosanct here. Please refer to my answer to the original poster in about 5 minutes!
 
A little perhaps. If you use the long form it is an instance assignment but the short form acts essentially as a conversion function - cf. New String(chr_array).

The exception is thrown if you declare the websites array without bounds. It isn't coming from the commandlist declaration itself. The following works only if the array is declared with the exact number of items it contains (3 in this case enumerated 0 to 2)



Imports System.Speech.Recognition.SrgsGrammar


Public Class Form1


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim websites(2) As String
websites(0) = "First"
websites(1) = "Second"
websites(2) = "Third"




Dim commandlist As New SrgsOneOf(websites)


End Sub
End Class
 
If you use the long form it is an instance assignment but the short form acts essentially as a conversion function
That is not true, the difference in those two statements is that one is qualifying the namespace, the other is not (implying the namespace must be imported). Code-wise they are equal.
 
If you want to insist on form over function then that's your prerogative. I should point however that I did very carefully say "acts as" rather than "is" which is how you seem to have interpreted it. As far as I'm concerned nothing is equal 'code-wise' that does not do exactly the same thing in the same place in the same conditions. You cannot substitute one for the other here. That's the bottom line. I'm sure in most cases on this forum people prefer what works to what may seem more 'correct' to VB 'grammarians'.
 
I should point however that I did very carefully say "acts as" rather than "is" which is how you seem to have interpreted it.
You said they were different, which they are not.
As far as I'm concerned nothing is equal 'code-wise' that does not do exactly the same thing in the same place in the same conditions. You cannot substitute one for the other here.
That is exactly the point, those two pieces of code are for all practical purposes completely identical. There is no substitution because they are the same. Both is invoking the same SrgsOneOf constructor with same argument.
You can't use any type in VB without qualifying it by namespace, there are three ways to do this, (a) directly qualifying it when declaring the variable, (a) by using the Imports statement in a code file, or (c) by importing the namespace globally in project settings. Commonly used namespaces are imported by default for the different project types. If one use a namespace a lot in a code file is it natural to use the Imports statement to avoid code getting too "wordy".
Here you can start learning about namespaces: Namespaces in Visual Basic
 
I have a string array - websites() - and for each string in this array, I want to add it to the commandlist
SrgsOneOf is used for alternate words to match a single rule, is that what you're trying to do?
 
SrgsOneOf is used for alternate words to match a single rule, is that what you're trying to do?
SrgsOneOf is used for alternate words to match a single set of rules, but not one single rule. The set of rules are then uploaded to a grammar set which then ties into Windows7 Speech Recognition Software. In the past, I had to type in something like this:

Dim commandlist As New Recognition.SrgsGrammar.SrgsOneOf(websites(0), websites(1), websites(2))
commandRule.Add(commandlist)
gram.Rules.Add(commandRule)
gram.Root = commandRule
recog.LoadGrammar(New Recognition.Grammar(gram))

The issue with this for my case is that the number of items in my database, websites() is dynamic, and it is incorrect of me to change the code every time I want to add a freaking website to the array. So I need to find a way to upload every string from the array websites() to SrgsOneOf, so that I can then upload them into my grammar rules. Seems simple, but it has proven to cause some trouble thus far.

In response to the debate above, you are correct in saying that there is no actual difference in the two methods, but rather that it offers a method to which one can clean up the code by eliminating the words System.blahblahblah before each reference. That is why I was confused at first, because at first glance there is no difference. I tried it for the hell of it and I was correct in believing that there was no difference (at least of relevance to my case) because it did not solve the problem.
 
Back
Top