How to cancel/abort Text to Speech

When executing the code sometimes with long text I need to cancel the text to speech. How can I make this happen. I have included what I have so far.
Dim objVo As Object
Dim SpeakUpdate As String
Dim strPhrase As String
Dim intPitch As Integer

SpeakUpdate = Me.caseupdate
intPitch = 2

Set objVo = CreateObject("SAPI.SpVoice")
objVo.Speak "<pitch middle = '" & intPitch & "'/>" + SpeakUpdate

Open in new window

seanlhallAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Vadim RappConnect With a Mentor Commented:
Unless you have added the reference to the voice library to the project, you have to define SVSFlagsAsync. Also, if you use objVo from another sub, it has to be declared on module level. We have verified that the following code works as you want, i.e. you can click the button "stop" during the playback, and that stops it.

Dim objVo As Object

Private Sub Talk_Click()
    Set objVo = CreateObject("SAPI.SpVoice")
    Const SVSFlagsAsync As Integer = 1
    objVo.Speak "some long text", SVSFlagsAsync
End Sub

Private Sub Stop_Click()
    objVo.Pause
End Sub

Open in new window

0
 
unknown_routineCommented:
objVo.Speak "", SVSFPurgeBeforeSpeak
0
 
seanlhallAuthor Commented:
That looks like what I am looking for.  I am not sure what to do with it though.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
seanlhallAuthor Commented:
When the speech is going I can not click on anything until it is done.
0
 
Vadim RappCommented:
Initiate method "speak" with asynchronous flag (SVSFlagsAsync); to interrupt, call Pause method.
0
 
seanlhallAuthor Commented:
When it starts to speak, I am unable to click anything until it is done. How would I call Pause?
0
 
Vadim RappCommented:
Do you call it with SVSFlagsAsync ?
0
 
seanlhallAuthor Commented:
Here is what I have now. When it starts talking I can not click anything until it is done talking.

Private Sub Talk_Click()
Dim objVo As Object
Dim SpeakUpdate As String
Dim strPhrase As String
Dim intPitch As Integer

SpeakUpdate = Me.caseupdate
intPitch = 2

Set objVo = CreateObject("SAPI.SpVoice")
objVo.Speak "<pitch middle = '" & intPitch & "'/>" + SpeakUpdate, SVSFlagsAsync

End Sub

Private Sub Stop_Click()
objVo.Speak "", SVSFPurgeBeforeSpeak
End Sub

Open in new window

0
 
seanlhallAuthor Commented:
Thanks I understand now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.