Share via


SpVoice Priority property (SAPI 5.3)

Microsoft Speech API 5.3

Object: SpVoice

Priority Property

The Priority property gets and sets the priority level of the voice.

The priority level defines the order in which the text-to-speech (TTS) engine processes a voice object's speech requests relative to requests from other voice objects. Higher priority levels are assigned to error-handling voices and the lowest priority level is assigned to normal voices. Because of their priority level, voice requests from error-handling voices are spoken ahead of normal priority voice requests; as a result, error-handling voices can appear to interrupt normal voices.

The voice priority levels are contained in the SpeechVoicePriority enumeration. An SpVoice object is created with normal priority. To create an alert or over voice, create a voice and set its Priority property appropriately.

Syntax

Set: SpVoice.Priority = SpeechVoicePriority
Get: SpeechVoicePriority = SpVoice.Priority

Parts

  • SpVoice
    The owning object.
  • SpeechVoicePriority
    Set: A SpeechVoicePriority constant that sets the priority level.
    Get: A SpeechVoicePriority constant that returns the current priority level.

Remarks

A voice with a Priority setting of SVPAlert is referred to as an alert voice. Alert voices are designed to be the primary vehicle for TTS error-handling. Other SpVoice elements, such as the AlertBoundary property, support error-handling functionality in alert voices that is not available to other voices.

Example

The following Visual Basic form code demonstrates the use of the Priority 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 Form_Load procedure creates three voice objects and assigns different Voice and Priority settings to each. Each voice is named after its Priority setting.

In the Command1_Click event procedure, the normal voice begins speaking asynchronously. The alert voice waits a few seconds and then begins speaking. The normal voice is interrupted by the alert voice and resumes speaking when the alert voice has finished.

In the Command2_Click event procedure, the normal voice and the over voice begin speaking asynchronously. The alert voice waits a few seconds and then begins speaking. The normal voice is interrupted by the alert voice and resumes speaking when the alert voice has finished. The over voice speaks over, or mixes with, the other two voices.

Please see the AlertBoundary property for another code example using the Priority property.

  
Option Explicit

Dim Normal As SpeechLib.SpVoice
Dim Alert As SpeechLib.SpVoice
Dim Over As SpeechLib.SpVoice

Private Sub Form_Load()
    On Error GoTo EH

    Set Normal = New SpVoice
    Set Alert = New SpVoice
    Set Over = New SpVoice

    Alert.Priority = SVPAlert   'From SVPNormal to SVPAlert
    Over.Priority = SVPOver     'From SVPNormal to SVPOver

    'Presumes two male voices and one female voice
    Set Normal.Voice = Normal.GetVoices("gender = male").Item(0)    '1st male voice
    Set Alert.Voice = Alert.GetVoices("gender = male").Item(1)      '2nd male voice
    Set Over.Voice = Normal.GetVoices("gender = female").Item(0)    '1st female voice

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command1_Click()
    On Error GoTo EH

    'Enqueue streams from normal voice
    Normal.Speak "a normal voice. a normal priority voice.", SVSFlagsAsync
    Normal.Speak "a normal voice. a normal priority voice.", SVSFlagsAsync

    Call Wait(3)    'Alert voice interrupts normal
    Alert.Speak "excuse me, alert voice!", SVSFlagsAsync

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command2_Click()
    On Error GoTo EH

    'Enqueue streams from Normal voice and Over voice
    Normal.Speak "a normal voice. a normal priority voice.", SVSFlagsAsync
    Normal.Speak "a normal voice. a normal priority voice.", SVSFlagsAsync

    Over.Speak "over voice speaking over the other voices.", SVSFlagsAsync
    Over.Speak "over voice speaking over the other voices.", SVSFlagsAsync
    Over.Speak "over voice speaking over the other voices.", SVSFlagsAsync

    Call Wait(3)    'Alert voice interrupts normal
    Alert.Speak "excuse me, alert voice!", SVSFlagsAsync

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Wait(ByVal Seconds As Integer)
    On Error GoTo EH

    Dim sglWait As Single
    sglWait = Timer() + Seconds
    Do
        DoEvents
    Loop Until Timer > sglWait

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