Solved

How to cancel/abort Text to Speech

Posted on 2013-10-25
10
523 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:seanlhall
  • 5
  • 3
10 Comments
 
LVL 15

Expert Comment

by:unknown_routine
ID: 39600390
objVo.Speak "", SVSFPurgeBeforeSpeak
0
 

Author Comment

by:seanlhall
ID: 39600446
That looks like what I am looking for.  I am not sure what to do with it though.
0
 

Author Comment

by:seanlhall
ID: 39600998
When the speech is going I can not click on anything until it is done.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39607455
Initiate method "speak" with asynchronous flag (SVSFlagsAsync); to interrupt, call Pause method.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:seanlhall
ID: 39608416
When it starts to speak, I am unable to click anything until it is done. How would I call Pause?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39608440
Do you call it with SVSFlagsAsync ?
0
 

Author Comment

by:seanlhall
ID: 39608539
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
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
ID: 39608704
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
 

Author Closing Comment

by:seanlhall
ID: 39608762
Thanks I understand now.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now