Link to home
Start Free TrialLog in
Avatar of codefinger
codefingerFlag for United States of America

asked on

Why is confidence always -1?

Almost have my speech class working just as I want it to, but I am puzzled because the confidence level is always -1, even when the phrase is recognized.   What am I missing?


Imports SpeechLib
Public Class SpeechClass
    Private _commands As Speech.Recognition.Choices
    Private _gbldr As Speech.Recognition.GrammarBuilder
    Private WithEvents RecoContext As SpSharedRecoContext
    Public WithEvents _recnizer As New Speech.Recognition.SpeechRecognizer
    Private _grm As System.Speech.Recognition.Grammar
    Private vLastCommand As String
    Private vConfidence As Integer = 0
    Public Property ValidCommands() As Speech.Recognition.Choices
        Get
            Return _commands
        End Get
        Set(ByVal value As Speech.Recognition.Choices)
            _commands = value
        End Set
    End Property
    Public Property LastCommand() As String
        Get
            Return vLastCommand
        End Get
        Set(ByVal value As String)
            vLastCommand = value
        End Set
    End Property
    Public Property Confidence() As Integer
        Get
            Return vConfidence
        End Get
        Set(ByVal value As Integer)
            vConfidence = value
        End Set
    End Property

    Public Function Initialize(ByRef str_response As String) As Boolean
        Dim retval As Boolean = True

        Try
            _commands = New Speech.Recognition.Choices
            _commands.Add("Computer")
            RecoContext = New SpSharedRecoContext
            _gbldr = New System.Speech.Recognition.GrammarBuilder(_commands)
            _grm = New System.Speech.Recognition.Grammar(_gbldr)
            _grm.Enabled = True
            _recnizer.LoadGrammar(_grm)

        Catch ex As Exception
            retval = False
            str_response = ex.Message
            If Not ex.InnerException Is Nothing Then
                str_response = str_response & vbCrLf & ex.InnerException.Message
            End If
        End Try
        Return retval
    End Function
    Public Function StartRecognition(ByRef str_response As String) As Boolean
        Dim retval As Boolean = True
        Try

            _grm.Enabled = True

        Catch ex As Exception
            retval = False
            str_response = ex.Message
            If Not ex.InnerException Is Nothing Then
                str_response = str_response & vbCrLf & ex.InnerException.Message
            End If
        End Try
        Return retval
    End Function
    Public Function AddCommand(ByVal str_command As String, ByRef str_response As String) As Boolean
        Dim retval As Boolean = True

        Try

            _commands.Add(str_command)
            _gbldr = New System.Speech.Recognition.GrammarBuilder(_commands)
            _grm = New System.Speech.Recognition.Grammar(_gbldr)
            _recnizer.LoadGrammar(_grm)

        Catch ex As Exception
            retval = False
            str_response = ex.Message
            If Not ex.InnerException Is Nothing Then
                str_response = str_response & vbCrLf & ex.InnerException.Message
            End If
        End Try

        Return retval
    End Function
    Public Function StopRecognition(ByRef str_response As String) As Boolean

        _grm.Enabled = False

    End Function
    Private Sub RecoContext_Recognition(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult) Handles RecoContext.Recognition

    End Sub

    Private Sub RecoContext_SoundStart(ByVal StreamNumber As Integer, ByVal StreamPosition As Object) Handles RecoContext.SoundStart

    End Sub

    Private Sub _recnizer_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles _recnizer.SpeechRecognized

        LastCommand = e.Result.Text.ToUpper()
        Confidence = e.Result.Confidence      '<<< always -1 why?
        MsgBox("I heard " & e.Result.Text)


    End Sub
End Class

Open in new window

Avatar of SameerJagdale
SameerJagdale
Flag of United States of America image

you have to set RequiredConfidence property. if this is not set then it will always set to default as -1 which is low 1.
Avatar of codefinger

ASKER

How?  From what I have been able to Google so far, RequiredConfidence is a Read-Only property.
ASKER CERTIFIED SOLUTION
Avatar of SameerJagdale
SameerJagdale
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for sticking with this Mr. Jaqdale.   I apologize for my apparent density, but I am not sure exactly how the link you provided answers the question I asked....how do I set the RequiredConfidence?

Can you possibly show me some code that demonstrates how this is done?   I would rather not have to install another speech engine (as seems to be suggested by the link)...I am short on hard drive space as it is!

Again, thank you.   I am looking forward to your reply.


hello,
the confidence level can be an engine confidence or required confidence. the first one was for requiredconfidence and the second one was for engine confidence.
i cannot test it at my end / use your code since i don't have the speech SDK. What i come to know if you must have an SDK that is compatible with office in order to recognize the speech.,let me try to find out more specific information, if i can .. it might take a while though :-)
Expert comments were helpful,  but expert promised to do research and never returned to the question.  I am closing it now.
Avatar of Hossbot
Hossbot

I encountered this exact issue. Before I explain further, its important to understand that SAPI is an API and is not the speech recognition engine (SRE). There are several SRE out there that work with SAPI 5.x, even 3rd party ones not from Microsoft.

When you install SAPI 5.1, the Microsoft English Recognizer v5.1 SRE is installed. But, this SRE does not support confidence score. You need the Microsoft English (U.S.) v6.1 Recognizer SRE as it is the first SRE from Microsoft that I know of that supports confidence score. Only place I know of to get it is from the Office 2003 CD (I've only tried the Pro edition).

To verify which version you have installed and which one is being used by SAPI, open the control panel and open the Speech applet. On the Speech Recognition tab, the top most drop down lists all the SRE installed on your PC and which ever one is selected is the one that SAPI will use.

To install the Microsoft English (U.U.) v6.1 Recognizer SRE from the Office 2003 disc without actually installing office, perform the following...
  • Run the CD through Autorun or by clicking Setup.exe within the disk
  • Choose Custom Install when prompted and click next
  • Uncheck all applications including Word, Excel, Outlook, PowerPoint, Publisher, Access & InfoPath (where applicable) and check the box to Choose advanced customization of applications and click next
  • Click the + next to Office Shared Features and the + next to Alternative User Input
  • Verify Speech is set to "Run from My Computer"
  • Click Next and proceed with your installation
Hope this helps anyone else that comes across this page, it took me awhile to understand this from various forums and documentation.