SpeechRecoContext VoicePurgeEvent Property (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

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 (located in the file C:\sol.xml) so that the RecoContext can begin recognition as soon as the grammar is activated. Both command button Click event procedures speak text that 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.


Option Explicit

Dim WithEvents Voice As SpVoice
Dim Context As SpSharedRecoContext
Dim RecoGrammar As ISpeechRecoGrammar

Const SpeakStr1 = "Recognition is started by the next bookmark."
Const SpeakStr2 = " but the voice keeps speaking."

Private Sub Form_Load()
    On Error GoTo EH

    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

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command1_Click()
    On Error GoTo EH

    ' Speak with no VoicePurgeEvent:
    Context.VoicePurgeEvent = 0
    Voice.Speak SpeakStr1, SVSFIsXML + SVSFlagsAsync
    Voice.Speak SpeakStr2, SVSFIsXML + SVSFlagsAsync
    Voice.WaitUntilDone (999)
    RecoGrammar.CmdSetRuleState "", SGDSInactive

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command2_Click()
    On Error GoTo EH

    ' Speak with VoicePurgeEvent on SRESoundStart:
    Context.VoicePurgeEvent = SRESoundStart
    Voice.Speak SpeakStr1, SVSFIsXML + SVSFlagsAsync
    Voice.Speak SpeakStr2, SVSFIsXML + SVSFlagsAsync
    Voice.WaitUntilDone (999)
    RecoGrammar.CmdSetRuleState "", SGDSInactive

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Voice_Bookmark _
   (ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal Bookmark As String, _
    ByVal BookmarkId As Long)

    On Error GoTo EH

    ' After the first bookmark, we activate the grammar,
    ' and the SR sound start event should pause TTS voice.
    RecoGrammar.CmdSetRuleState "", SGDSActive  'active the rule

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub ShowErrMsg()

    ' Declare identifiers:
    Dim T As String

    T = "Desc: " & Err.Description & vbNewLine
    T = T & "Err #: " & Err.Number
    MsgBox T, vbExclamation, "Run-Time Error"
    End

End Sub