7 Replies - 10740 Views - Last Post: 30 July 2009 - 01:12 PM Rate Topic: -----

#1 al2021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-September 08

Using Custom Grammar for Speech Recognition

Post icon  Posted 24 September 2008 - 03:55 PM

Hi --

I have been away from programming for many years and I am trying to develop a simple speech recognition app in visual basic. Here is the problem that I am experiencing:

Com Exception was unhandled:
Exception from HRESULT: 0x80045048

My code:

Imports System.Xml

'Custom Imports
Imports SpeechLib


Public Class Form1

    'Declares

    Dim WithEvents RecoContext As SpSharedRecoContext       'The Main Recognition Object Used throughout the whole program. -- Shared Object: More Info on this later.
    Dim Grammar As ISpeechRecoGrammar                       'The Grammar Object so the program knows what is going on. -- Instanced Object: More Info on this later.
    Dim CharCount As Integer                                'This is used to count the amount of chars that are in the text box.
    Public Const SGDSActive As SpeechLib.SpeechRuleState = 0
    Public Const SGDSInactive As SpeechLib.SpeechRuleState = 1
    Public Const SLOStatic As SpeechLib.SpeechLoadOption = 1

    'Start Button. This will engage reco, and start the entire process.
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click



        'First check to see if reco has been loaded before,if not load it.
        If (RecoContext Is Nothing) Then
            RecoContext = New SpSharedRecoContextClass          'Create a new Reco Context Class
            Grammar = RecoContext.CreateGrammar(1)              'Setup the Grammar
            Grammar.CmdLoadFromFile("E:\myGrammar.XML", SpeechLoadOption.SLOStatic)   'Load the Grammar

        End If

        lblStatus.Text = "Recognition Started"                  'Change the Label to let the user know whats up
        Grammar = RecoContext.CreateGrammar
        Grammar.CmdLoadFromFile("myGrammar.XML", SLOStatic)
        Grammar.CmdSetRuleIdState(101, SGDSActive)        'Turns on the Recognition. This is Vitally important
        
        'This is so the user doesn't break the program by
        'trying to start the recognition after its already started.
        btnStart.Enabled = False
        btnStop.Enabled = True
    End Sub


    ''''


    'Stop Button. This will stop the recoginition
    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

        Grammar.DictationSetState(SpeechRuleState.SGDSInactive)  'Turns off the Recognition. It will go dormant.
        lblStatus.Text = "Recognition Stopped"                  'Change the label to let the user know whats up

        'Again This is so the user doesn't go breaking things accidently
        btnStart.Enabled = True
        btnStop.Enabled = False
    End Sub


    ''''


    'This is the hypothesis sub. The hypothesis is not the final recognition. This will fire many times per word. You do not want to print anything that is final from the hypothesis.
    'This is not required for the final recognition. But it is vital to understand it.
    Private Sub OnHypo(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal Result As ISpeechRecoResult) Handles RecoContext.Hypothesis

        btnStop.Enabled = False    'Don't allow the user to stop the recognition until it has completed.
        'The button will re-enable in the OnReco Event

        'This is so you don't keep printing the same text over and over.
        If lblStatus.Text <> "Receiving" Then
            lblStatus.Text = "Receiving"
        End If
    End Sub


    ''''


    'This sub is fired when the reco engine detects a set of words. This is what you want to use to print or sendkey.
    'Use this sub for the final printing of words.
    Private Sub OnReco(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult) Handles RecoContext.Recognition

        Dim recoResult As String = Result.PhraseInfo.GetText 'Create a new string, and assign the recognized text to it.

        'This block will print to the textbox built into the program
        'If you would prefer to use the SendKeys method, Comment out this entire block. And Uncomment the SendKeys Line.
        txtBox.Selectionstart = CharCount
        txtBox.SelectedText = recoResult & " "
        CharCount = CharCount + 1 + Len(recoResult)

        'Uncomment the next line if you want to send the text to the selected window rather than constrain it to the textbox.
        'SendKeys.Send(recoResult & " ") 'This line sends the result via SendKeys to the top window.

        lblStatus.Text = "Finished Dictating"
        btnStop.Enabled = True
    End Sub

End Class



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Using Custom Grammar for Speech Recognition

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Using Custom Grammar for Speech Recognition

Posted 25 September 2008 - 05:52 AM

Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#3 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 57
  • View blog
  • Posts: 1,243
  • Joined: 05-June 08

Re: Using Custom Grammar for Speech Recognition

Posted 25 September 2008 - 04:13 PM

theres a nice tutorial on this in the tutorial section
Was This Post Helpful? 0
  • +
  • -

#4 al2021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-September 08

Re: Using Custom Grammar for Speech Recognition

Posted 25 September 2008 - 06:35 PM

View PostDamage, on 25 Sep, 2008 - 04:13 PM, said:

theres a nice tutorial on this in the tutorial section


Thanks Damage - this is where I started. I can get dictation to work but I can't get a custom grammar to work. The code compiles OK but I get the run time error:
Com Exception was unhandled:
Exception from HRESULT: 0x80045048
Was This Post Helpful? 0
  • +
  • -

#5 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 57
  • View blog
  • Posts: 1,243
  • Joined: 05-June 08

Re: Using Custom Grammar for Speech Recognition

Posted 26 September 2008 - 01:09 AM

well i found a similar thread at codeproject and their solution was

Quote

I fixed my exception by downloading and installing the 5.1 SDK. I had a 5.0 sapi.dll, which was upgraded to 5.1.4111.0.

Was This Post Helpful? 0
  • +
  • -

#6 al2021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-September 08

Re: Using Custom Grammar for Speech Recognition

Posted 04 November 2008 - 07:48 PM

I have 5.1 SDK loaded but still can't get the C&C to work. Dictation works fine but not hte C&C.


View PostDamage, on 26 Sep, 2008 - 12:09 AM, said:

well i found a similar thread at codeproject and their solution was

Quote

I fixed my exception by downloading and installing the 5.1 SDK. I had a 5.0 sapi.dll, which was upgraded to 5.1.4111.0.

Was This Post Helpful? 0
  • +
  • -

#7 p00m  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-April 09

Re: Using Custom Grammar for Speech Recognition

Posted 18 April 2009 - 05:22 AM

View Postal2021, on 4 Nov, 2008 - 06:48 PM, said:

I have 5.1 SDK loaded but still can't get the C&C to work. Dictation works fine but not hte C&C.


View PostDamage, on 26 Sep, 2008 - 12:09 AM, said:

well i found a similar thread at codeproject and their solution was

Quote

I fixed my exception by downloading and installing the 5.1 SDK. I had a 5.0 sapi.dll, which was upgraded to 5.1.4111.0.


I have the same problem. Have the 5.1 SDK installed and am also getting the
"Exception from HRESULT: 0x80045048"-error on

Grammar.CmdLoadFromFile("C:\Grammar.XML", SpeechLoadOption.SLOStatic)


Any help would be great. It works fine with the default Grammar.
Was This Post Helpful? 0
  • +
  • -

#8 Umaid123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 15-December 08

Re: Using Custom Grammar for Speech Recognition

Posted 30 July 2009 - 01:12 PM

I am having sa,e problem while adding my own custom xml grammar and getting HResult error : 0x80045048

My XML:
<?xml version="1.0" encoding="utf-8" ?>
<GRAMMAR LANGID="409">
<RULE ID="1" NAME="CHECK1" TOPLEVEL="ACTIVE">
<P PROPNAME="request" VAL="meeting">schedule a meeting</P>
<P>with</P>
<L PROPNAME="participants">
<P VAL="AmyAnd">Amy Anderson</P>
<P VAL="tbremer">Ted Bremer</P>
<P VAL="fralee">Frank Lee</P>
<P VAL="crandall">Cynthia Randall</P>
<P VAL="swhite">Suki White</P>
<P VAL="kyoshida">Kim Yoshida</P>
</L>
</RULE>
</GRAMMAR>


View Postp00m, on 18 Apr, 2009 - 04:22 AM, said:

View Postal2021, on 4 Nov, 2008 - 06:48 PM, said:

I have 5.1 SDK loaded but still can't get the C&C to work. Dictation works fine but not hte C&C.


View PostDamage, on 26 Sep, 2008 - 12:09 AM, said:

well i found a similar thread at codeproject and their solution was

Quote

I fixed my exception by downloading and installing the 5.1 SDK. I had a 5.0 sapi.dll, which was upgraded to 5.1.4111.0.


I have the same problem. Have the 5.1 SDK installed and am also getting the
"Exception from HRESULT: 0x80045048"-error on

Grammar.CmdLoadFromFile("C:\Grammar.XML", SpeechLoadOption.SLOStatic)


Any help would be great. It works fine with the default Grammar.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1