Solved

How to cancel/abort Text to Speech

Posted on 2013-10-25
10
563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 40

Expert Comment

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

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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

635 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