SpeechRecoContext VoicePurgeEvent Property

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoContext

VoicePurgeEvent Property


The VoicePurgeEvent property gets and sets the RecoContext event which will stop the RecoContext's voice and purge the voice queue.

Applications can use the Voice property of a RecoContext object to prompt a user for spoken input. Setting the VoicePurgeEvent to the SRESoundStart event will cause the RecoContext's voice to stop speaking when the user begins speaking.

Syntax

Set: SpeechRecoContext.VoicePurgeEvent = SpeechRecoEvents
Get: SpeechRecoEvents = SpeechRecoContext.VoicePurgeEvent

Parts

SpeechRecoContext
The owning object.
SpeechRecoEvents
Set: A SpeechRecoEvents constant that sets the VoicePurgeEvent.
Get: A SpeechRecoEvents constant that gets the VoicePurgeEvent

Example

The following Visual Basic form code demonstrates the use of the VoicePurgeEvent property. To run this code, create a form with the following controls:

  • Two command buttons, called Command1 and Command2
  • Paste this code into the Declarations section of the form.

    The code creates a RecoContext with a grammar and a voice. The grammar is loaded with a set of rules so that the RecoContext can begin recognition as soon as the grammar is activated. Both command button procedures speak text which contains a bookmark. The RecoContext's bookmark event activates the grammar, which initiates recognition, and the activated RecoContext receives an SRESoundStart event.

    In the Command1_Click procedure, the voice continues speaking after recognition has begun, because the VoicePurgeProperty has been set to zero, and the SRESoundStart event does not effect either the RecoContext or its Voice. In the Command2_Click procedure, the VoicePurgeProperty causes the SRESoundStart event to stop the voice.

    Dim WithEvents Voice As SpVoice
    Dim Context As SpSharedRecoContext
    Dim RecoGrammar As ISpeechRecoGrammar
    
    Const SpeakStr1 = "Recognition is started by the next bookmark."
    Const SpeakStr2 = "<bookmark mark='first'/> but the voice keeps speaking."
                    
    Private Sub Command1_Click()
    
        'Speak with no VoicePurgeEvent
        
        Context.VoicePurgeEvent = 0
        Voice.Speak SpeakStr1, SVSFIsXML + SVSFlagsAsync
        Voice.Speak SpeakStr2, SVSFIsXML + SVSFlagsAsync
        Voice.WaitUntilDone (999)
        RecoGrammar.CmdSetRuleState "", SGDSInactive
        
    End Sub
    
    Private Sub Command2_Click()
    
        'Speak with VoicePurgeEvent on SRESoundStart
        
        Context.VoicePurgeEvent = SRESoundStart
        Voice.Speak SpeakStr1, SVSFIsXML + SVSFlagsAsync
        Voice.Speak SpeakStr2, SVSFIsXML + SVSFlagsAsync
        Voice.WaitUntilDone (999)
        RecoGrammar.CmdSetRuleState "", SGDSInactive
        
    End Sub
    
    Private Sub Form_Load()
    
        Set Context = New SpSharedRecoContext
        Set RecoGrammar = Context.CreateGrammar(123)
        RecoGrammar.CmdLoadFromFile "c:\sol.xml"
        
        'The voice must be
        Set Voice = Context.Voice
        Voice.EventInterests = SVEBookmark + SVEEndInputStream + SVEStartInputStream
        
    End Sub
    
    Private Sub Voice_Bookmark(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Bookmark As String, ByVal BookmarkId As Long)
        
        'after the first bookmark, we activate the grammar,
        'and the SR sound start event should pause TTS voice.
        RecoGrammar.CmdSetRuleState "", SGDSActive  'active the rule
        
    End Sub