Figure 4   Definitions and Initialization


'PowerPoint and Speech Object Definitions
 
 Dim App As PowerPoint.Application
 Public DirectSR As DirectSR
 Public DirectSS As DirectSS
 Dim SClass As New SpeechClass
 
 Public Sub Init()
    On Error GoTo ErrorMessage
    
     Dim Engine, Voice As Long
     Set DirectSR = New DirectSR
     Set DirectSS = New DirectSS
     Set SClass.DirectSR = DirectSR
     Set SClass.DirectSS = DirectSS
     Engine = DirectSR.Find("MfgName=Microsoft;Grammars=1")
     DirectSR.Select Engine
     DirectSR.GrammarFromFile "c:\Demos\computer.txt"
     DirectSR.Activate
     
     Voice = DirectSS.Find("MfgName=Microsoft;Gender=1")
     DirectSS.Select Voice
     
 GoTo NoError
 ErrorMessage:
 MsgBox "Unable to initialize speech recognition engine.
 Make sure an engine that supports speech recognition is installed."
 End
 NoError:

Figure 5   DirectSR_PhraseFinish


Private Sub DirectSR_PhraseFinish(ByVal flags As Long,
ByVal beginhi As Long, 
ByVal beginlo As Long, 
ByVal endhi As Long, 
ByVal endlo As Long, 
ByVal Phrase As String, 
ByVal parsed As String, 
ByVal results As Long)
 
 If (parsed = "") Then
 
 Else
     Select Case parsed
             
         Case "Computer"
         DirectSR.Deactivate
         DirectSS.Speak "I am listening"
         DirectSR.GrammarFromFile "c:\Demos\voice1.txt"
             
         Case "Sleep"
         DirectSR.Deactivate
         DirectSS.Speak "I am sleeping"
         DirectSR.GrammarFromFile "c:\Demos\computer.txt"
             
         Case "Next"
         PowerPoint.ActivePresentation.SlideShowWindow.View.Next
 
         Case "Back"
         PowerPoint.ActivePresentation.SlideShowWindow.View.Previous
 
         Case "Close"
         SendKeys "%{F4}"
 
     End Select
 End If
 End Sub