SpVoice AlertBoundary property (SAPI 5.3)
The AlertBoundary property gets and sets the alert boundary, which specifies how a speaking voice pauses for alerts.
Because a TTS application might operate without a graphical user interface (UI), it must be able to implement error handling with a TTS voice. The only capability needed for voice error messaging is the ability to interrupt another voice; this capability is assigned to a voice by setting the Priority property to SVPAlert. A voice with a priority setting of SVPAlert is referred to as an alert voice, or simply as an alert, because its purpose is identical to that of an alert box or message box.
When a speaking voice detects a pending alert interruption, it continues speaking until it arrives at a specific application-defined stopping point, such as a sentence or a word. This stopping point is called the alert boundary because it is the event boundary at which alerts can be processed.
The SpeechVoiceEvents enumeration contains the types of events that a voice object can receive. The AlertBoundary property consists of one of these constants. The default setting is SVEWordBoundary.
|Set:||SpVoice.AlertBoundary = SpeechVoiceEvents|
|Get:||SpeechVoiceEvents = SpVoice.AlertBoundary|
- The owning object.
Set: A SpeechVoiceEvents constant that sets the alert boundary.
Get: A SpeechVoiceEvents constant that gets the alert boundary.
The following code demonstrates the use of the Priority, EventInterests and AlertBoundary properties. The code uses the GetVoices method to select a male voice and a female voice, and sets the Priority property of the female voice to SVPAlert, making it an alert voice. The Priority of the male voice remains SVPNormal.
The code sets the EventInterests of the normal voice to SVEBookmark, so that it can receive bookmark events, and then speak a text string containing bookmarks. The normal voice's Bookmark event uses the alert voice to speak the bookmark data. Because the alert voice interrupts the normal voice, the normal voice is essentially using its own events to interrupt itself.
Note that the interruption does not occur immediately; the alert voice must first enqueue its text stream, and then the normal voice must detect the pending alert and stop speaking at the next alert boundary. The normal voice might speak several words or phonemes past the bookmark before it pauses for the alert voice to speak.
In this example, the normal voice can be interrupted on a phoneme boundary, which may divide a word. Changing the AlertBoundary to word or sentence boundaries will noticeably change the interaction of the two voices.
Option Explicit Dim WithEvents objHIM As SpeechLib.SpVoice 'Normal voice will receive events Dim objHER As SpeechLib.SpVoice 'Alert voice will not Private Sub Command1_Click() On Error GoTo EH Dim strSpeak As String 'Create an Alert Priority voice - female Set objHER = New SpVoice objHER.Priority = SVPAlert Set objHER.Voice = objHER.GetVoices("gender=female").Item(0) 'Create a Normal Priority voice - male Set objHIM = New SpVoice Set objHIM.Voice = objHIM.GetVoices("gender=male").Item(0) objHER.Speak "the priority of this voice is S V P alert" objHIM.Speak "the priority of this voice is S V P normal" objHIM.EventInterests = SVEBookmark 'Receive bookmark events only objHIM.AlertBoundary = SVEPhoneme 'Let alert voices interrupt words 'Normal voice speaks text which generates events. strSpeak = "This is text that contains bookmarks " _ & "for the purpose of generating events." objHIM.Speak strSpeak, SVSFIsXML + SVSFlagsAsync EH: If Err.Number Then ShowErrMsg End Sub Private Sub objHIM_Bookmark _ (ByVal StreamNumber As Long, _ ByVal StreamPosition As Variant, _ ByVal Bookmark As String, _ ByVal BookmarkId As Long) On Error GoTo EH objHER.Speak Bookmark, SVSFlagsAsync 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