Share via


SpVoice EventInterests property (SAPI 5.3)

Microsoft Speech API 5.3

Object: SpVoice

EventInterests Property

The EventInterests property gets and sets the types of events received by the SpVoice object.

When a text-to-speech (TTS) engine speaks a stream of text, it is constantly detecting certain conditions in the stream, such as the completion of phonemes, words and sentences. When it detects one of these conditions, the engine is able to generate a component object model (COM) event that will be received by the voice object that enqueued the stream.

When the engine detects a potential event condition in a stream, it checks the EventInterests property of the voice that enqueued the stream. If that event type is included in the voice object's event interests, the engine will generate an event of that type.

In Visual Basic, it is necessary to use the WithEvents keyword when dimensioning an SpVoice object intended to receive events. The default setting of the EventInterests property is 33278, or 0x081FE, which represents the sum of all SpeechVoiceEvents constants except SVEAudioLevel (a change in audio level).

Syntax

Set: SpVoice.EventInterests = SpeechVoiceEvents
Get: SpeechVoiceEvents = SpVoice.EventInterests

Parts

  • SpVoice
    The owning object.
  • SpeechVoiceEvents
    Set: One or more SpeechVoiceEvents setting the EventInterests.
    Get: A number equivalent to the SpeechVoiceEvents in the EventInterests.

Remarks

The values assigned to SpeechVoiceEvents constants are single-bit values, like 1, 2, 4, 8, 16, etc. Use a logical Or function to add them to EventInterests, and a logical XOr function to remove them. It should be noted that a logical Xor function does not zero a bit value, but toggles the value. Because of this, it is necessary to ensure that the bit value is set before attempting to zero it with an Xor.

Recognition contexts support an EventInterests property, which uses a similar syntax to specify interest in speech recognition events.

Example

The following Visual Basic form code demonstrates the syntax of the EventInterests property. Interest in individual events is set and reset using logical Or and Xor statements.

To run this code, create a single form without any controls on it. Paste this code into the Declarations section of the form.

  
Option Explicit

Dim objVoice As SpeechLib.SpVoice

Private Sub Form_Load()
    On Error GoTo EH

    Set objVoice = New SpVoice
    Call EventInterests

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub EventInterests()
    On Error GoTo EH

    With objVoice

        ' Add the SVEPhoneme and SVEViseme constants to Event Interests
        ' (setting bit with logical 'Or' doesn't require testing):
        .EventInterests = .EventInterests Or SVEPhoneme
        MsgBox .EventInterests, vbInformation
        .EventInterests = .EventInterests Or SVEViseme
        MsgBox .EventInterests, vbInformation

        ' Remove the SVEViseme constant from Event Interests
        ' (zeroing bit with logical 'Xor' requires testing!)--
        If (.EventInterests And SVEViseme) = SVEViseme Then
            .EventInterests = .EventInterests Xor SVEViseme
            MsgBox .EventInterests, vbInformation
        End If

    End With

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