I have limited experience with the SpeechRecognitionEngine class, but I toyed with it a bit... one thing I've notice is that grammar entries are not necessary "flat", but can be composed with layers of separate choices and bits which are then compiled by the engine; not sure if this is just for convenience in code, or if has actual effect on reliability
Now, maybe you are already doing your in this exact way, but this is a small example that seems fairly accurate on my system (in VB because I'm faster that way, trivial to convert to C#):
Private WithEvents speechEngine As New Speech.Recognition.SpeechRecognitionEngine
Private WithEvents speechSynt As New Speech.Synthesis.SpeechSynthesizer
'------------------------------------------------
'somewhere in your inizialization section
'------------------------------------------------
speechEngine.SetInputToDefaultAudioDevice()
'Sets a medium-high confidence factor
speechEngine.UpdateRecognizerSetting("CFGConfidenceRejectionThreshold", 70)
speechSynt.SetOutputToDefaultAudioDevice()
Dim gramBuilder As GrammarBuilder
Dim ch_Numbers As New Choices()
ch_Numbers.Add("1", "2", "3", "4", "5", "6", "7", "8", "9")
Dim ch_Letters As New Choices()
ch_Letters.Add("Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India" _
, "Juliett", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo" _
, "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "Xray", "Yankee", "Zulu")
gramBuilder = New GrammarBuilder
gramBuilder.Append("what Is")
gramBuilder.Append(ch_Numbers)
gramBuilder.Append("plus")
gramBuilder.Append(ch_Numbers)
Dim g_WhatIsXplusY As New Grammar(gramBuilder)
Debug.WriteLine(gramBuilder.DebugShowPhrases)
gramBuilder = New GrammarBuilder
gramBuilder.Append(ch_Numbers)
gramBuilder.Append(ch_Numbers)
gramBuilder.Append(ch_Letters)
Dim g_MilitaryUnits As New Grammar(gramBuilder)
Debug.WriteLine(gramBuilder.DebugShowPhrases)
speechEngine.LoadGrammarAsync(g_WhatIsXplusY)
speechEngine.LoadGrammarAsync(g_MilitaryUnits)
speechEngine.RecognizeAsync(RecognizeMode.Multiple)
'------------------------------------------------
'handlers for the SpeechEngine events
'------------------------------------------------
Private Sub speechEngine_SpeechRecognized(sender As Object, e As SpeechRecognizedEventArgs) Handles speechEngine.SpeechRecognized
Dim txt As String = e.Result.Text
If txt.IndexOf("what") >= 0 AndAlso txt.IndexOf("plus") >= 0 Then
Dim words As String() = txt.Split(" "c)
Dim num1 As Integer = Integer.Parse(words(2))
Dim num2 As Integer = Integer.Parse(words(4))
Dim sum As Integer = num1 + num2
Dim output As String = String.Format("{0} plus {1} equals {2}", words(2), words(4), sum)
Debug.WriteLine(String.Format("(Speaking: {0})", output))
speechSynt.SpeakAsync(output)
Exit Sub
End If
Dim regex As New System.Text.RegularExpressions.Regex("^(\d{1}) (\d{1}) (\w+)$")
Dim match As System.Text.RegularExpressions.Match = regex.Match(txt)
If match.Success Then
Dim output As String = String.Format("Platoon {0}, unit {1}, company {2}: reporting in", match.Groups(1), match.Groups(2), match.Groups(3))
Debug.WriteLine(String.Format( "(Speaking: {0})", output))
speechSynt.SpeakAsync(output)
Exit Sub
End If
End Sub
Private Sub speechEngine_SpeechRecognitionRejected(sender As Object, e As SpeechRecognitionRejectedEventArgs) Handles speechEngine.SpeechRecognitionRejected
Debug.WriteLine("Speech input was rejected")
For Each phrase As RecognizedPhrase In e.Result.Alternates
If phrase.Text.Length > 0 Then
Debug.WriteLine(String.Format(" Rejected phrase: '{0}' confidence {1:N2}", phrase.Text, phrase.Confidence))
End If
Next
End Sub
It is true that the engine is a bit eager to please, so phrases like "1 sierra lima" tends to be recognized with fairly high confidence values, even if that is not really the format you would accept... this, I'm afraid, I'm not really sure how sghould be handled, if again is a matter of building the grammar with a differente structure or something else.