Share via


SpVoice Pause method (SAPI 5.3)

Microsoft Speech API 5.3

Object: SpVoice

Pause Method

The Pause method pauses the voice at the nearest alert boundary and closes the output device, allowing it to be used by other voices.

  
    SpVoice.Pause()

Parameters

None.

Return Value

None.

Example

The following Visual Basic form code demonstrates the use of the Pause and Resume methods. To run this code, create a form with the following control:

  • A command button called Command1

Paste this code into the Declarations section of the form.

The Form_Load procedure creates a voice object. The first call of the Command1_Click procedure causes the voice to begin speaking a text stream. Subsequent Command1 clicks alternately pause and resume the voice. When the voice has finished speaking the stream, the EndStream event procedure causes the voice to speak it again.

The voice's AlertBoundary setting of SVEPhoneme means that the Pause method can interrupt the voice within word boundaries. The text stream spoken contains a number of long words in order to show this interruption of words more clearly.

  
Option Explicit

Private WithEvents V As SpeechLib.SpVoice

Private Sub Command1_Click()
    On Error GoTo EH

    Select Case Command1.Caption

        Case "Start"
            Call SpeakAgain
            Command1.Caption = "Pause"

        Case "Pause"
            V.Pause
            Command1.Caption = "Resume"

        Case "Resume"
            V.Resume
            Command1.Caption = "Pause"

    End Select

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Form_Load()
    On Error GoTo EH

    Set V = New SpVoice
    V.AlertBoundary = SVEPhoneme    'Let words be interrupted
    Command1.Caption = "Start"

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub V_EndStream _
   (ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant)

    Call SpeakAgain

End Sub

Private Sub SpeakAgain()
    On Error GoTo EH

    V.Speak "this phenomenal asynchronous stream contains multisyllabic " _
            & "pronunciations and circumlocutions.", 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