SpVoice SynchronousSpeakTimeout property (SAPI 5.4)
Microsoft Speech API 5.4
The SynchronousSpeakTimeout property gets and sets the interval, in milliseconds, after which the voice's synchronous Speak and SpeakStream calls will time out when its output device is unavailable.
When a voice enqueues a text stream, the audio output device represented by its AudioOutput property may be in use. When the text stream is enqueued synchronously, the voice will wait for the amount of time specified in its SynchronousSpeakTimeout property. If the output device does not become available to the voice before the time has elapsed, the voice will time out, the synchronous speech request is cancelled, and the application receives an SPERR_DEVICE_BUSY error. This and other SAPI errors are detailed in Error Codes
There is no equivalent timeout for asynchronous speech. Because synchronous speech prevents applications from receiving events from mouse movements and keyboard input, unexpected voice streams from other applications could freeze an application attempting synchronous speech. The SynchronousSpeakTimeout is designed so that applications can recover from such situations.
|Set:||SpVoice.SynchronousSpeakTimeout = Long|
|Get:||Long = SpVoice.SynchronousSpeakTimeout|
The owning object.
Set: A Long variable that sets the property value.
Get: A Long variable that gets the property value.
The following Visual Basic form code demonstrates the use of the SynchronousSpeakTimeout property. To run this code, create a form with the following controls:
- A list box control called List1
- A command button called Command1
Paste this code into the Declarations section of the form.
The Form_Load procedure creates three voices. The Command1_Click procedure starts the first voice speaking, which makes the audio output device unavailable to the other voices. The SynchronousSpeakTimeout property of the second voice is set to one millisecond, ensuring that it will time out before the first voice finishes speaking. The third voice simply waits for the first voice to finish, and then speaks.
The voices use a subroutine to speak; this subroutine adds each speech request to the list box and tests for the error that occurs when a voice times out.
Option Explicit Const SPERR_DEVICE_BUSY = &H80045006; Dim v1 As SpeechLib.SpVoice Dim v2 As SpeechLib.SpVoice Dim v3 As SpeechLib.SpVoice Private Sub Command1_Click() List1.Clear 'Voice 1 takes control of the audio Call SafeSpeak(v1, "This is voice number 1", SVSFlagsAsync) Call SafeSpeak(v1, "Voice 2 and voice 3 will wait for me", SVSFlagsAsync) v1.WaitUntilDone 100 'ensure that the voice 1 starts first 'Voice 2 starts waiting until voice 1 is done, 'but its timeout is very short -- 1 millisecond. 'So it times out before voice 1 is done. v2.SynchronousSpeakTimeout = 1 Call SafeSpeak(v2, "This is voice 2", SVSFDefault) Call SafeSpeak(v2, "This is voice 2 again", SVSFDefault) 'Voice 3 simply waits until voice 1 is done. Call SafeSpeak(v3, "This is voice 3 now", SVSFDefault) End Sub Private Sub Form_Load() Set v1 = New SpVoice Set v2 = New SpVoice Set v3 = New SpVoice End Sub Private Sub SafeSpeak(who As SpVoice, ByVal txt, ByVal flags) On Error GoTo SafeSpeakExit DoEvents who.Speak txt, flags SafeSpeakExit: Select Case Err.Number Case 0: List1.AddItem "queued: " & txt Case SPERR_DEVICE_BUSY: List1.AddItem "timeout: " & txt End Select Err.Clear End Sub