Yes, the commented line should be green, I do not know why yours is not... Are you sure it is a simple (straight) apostrophe?
Here's my module, I'm pretty sure it is the same as yours:
Code:
|
Dim speech As SpVoice 'Don't overlook this line!
Sub SpeakText()
'Based on a macro by Mathew Heikkila
... See moreYes, the commented line should be green, I do not know why yours is not... Are you sure it is a simple (straight) apostrophe?
Here's my module, I'm pretty sure it is the same as yours:
Code:
|
Dim speech As SpVoice 'Don't overlook this line!
Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
If Len(Selection.Text) > 1 Then 'speak selection
speech.Speak Selection.Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
Else 'speak whole document
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
End If
Do
DoEvents
Loop Until speech.WaitUntilDone(10)
Set speech = Nothing
End Sub
Sub StopSpeaking()
'Based on a macro by Mathew Heikkila
'used to interrupt any running speech to text
'On Error Resume Next
speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set speech = Nothing
End Sub
|
|
What you mean exactly by „doesn't like”? It stops on that line when you try to stop the speech?
Pause/Break should be one of three keys grouped together above Insert/Home etc., together with PrScrn and ScrollLock. It is not present on every keyboard, especially laptops... ▲ Collapse | | Patricia Rosas امریکہ Local time: 02:35 انگریزیسےاسپینی + ... TOPIC STARTER میموریم میں
Jabberwock wrote:
Yes, the commented line should be green, I do not know why yours is not... Are you sure it is a simple (straight) apostrophe?
It was green after I saved it, but I didn't notice.
I used the organizer to erase the earlier module and then created a new one into which I pasted your code. When I first ran it, it said there was a compiler error and these lines are now RED:
speech.Speak Selection.Text, _
and
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _
Next, I put the cursor at the first line (Dim) and it jumps to the last end sub and says
"Only comments can appear after end sub, end function, or end property."
I am on a terrible deadline, but after Monday, I'll study up on how to use VB and then I'll come back and let you know if I've had any luck.
Thanks for your persistence and patience! | | | It seems two constants are not being defined | Jul 31, 2009 |
The code sample I mentioned before defines two additional constants at the top of the subroutines (the "Declaration" section). If you don't define SVSFlagsAsync and SVSFPurgeBeforeSpeak as constants, they are considered to be variables with an initial value of zero/null, so the values passed to the "speech" command are zero.
Try this:
Dim speech as SpVoice 'Don't overlook this line!
Const SVSFlagsAsync = 1
Const SVSFPurgeBeforeSpeak = 2
Sub ... See more The code sample I mentioned before defines two additional constants at the top of the subroutines (the "Declaration" section). If you don't define SVSFlagsAsync and SVSFPurgeBeforeSpeak as constants, they are considered to be variables with an initial value of zero/null, so the values passed to the "speech" command are zero.
Try this:
Dim speech as SpVoice 'Don't overlook this line!
Const SVSFlagsAsync = 1
Const SVSFPurgeBeforeSpeak = 2
Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
If Len(Selection.Text) > 1 Then 'speak selection
speech.Speak Selection.Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
Else 'speak whole document
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
End If
Do
DoEvents
Loop Until speech.WaitUntilDone(10)
Set speech = Nothing
End Sub
Sub StopSpeaking()
'Based on a macro by Mathew Heikkila
'used to interrupt any running speech to text
On Error Resume Next
speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set speech = Nothing
End Sub
The errors you were getting for the two lines ending in "_" are probably due to their being followed by a blank line, as "_" is the "line continuation" character. Thus, the truncated line has a blank continuation and generates an error. Make sure the only blank lines above are those preceding the "Sub" statements.
Daniel ▲ Collapse | |
|
|
Patricia Rosas امریکہ Local time: 02:35 انگریزیسےاسپینی + ... TOPIC STARTER میموریم میں Thanks, but it still doesn't work ... | Jul 31, 2009 |
Daniel,
I appreciate your help, but I cut and pasted your code in and still won't stop speaking. I must be doing something stupid. The speaking routine works perfectly. I'll try to figure this out once my Monday deadline is behind me.
But any further suggestions from anyone will be greatly appreciated!
Patricia | | | Vito Smolej جرمنی Local time: 10:35 رکن (2004) سلوویائیسےانگریزی + ... SITE LOCALIZER the two constants ... | Aug 1, 2009 |
Daniel Grau wrote:
The code sample I mentioned before defines two additional constants at the top of the subroutines (the "Declaration" section). If you don't define SVSFlagsAsync and SVSFPurgeBeforeSpeak as constants ...
are defined in the sapilib.dll dcom library, so including sapi defines them anyhow (*)
So ... what happens in StopSpeaking, if On Error Resume Next is commented out - like this
' On Error Resume Next
?
Regards
Vito
*: a line at the top, stating Option explicit would detect the "undefined" status by itself. | | | موضوع میں صفحات: < [1 2] | | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » Visual Basic Macro: Can someone debug it? Protemos translation business management system | Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!
The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.
More info » |
| Trados Studio 2022 Freelance | The leading translation software used by over 270,000 translators.
Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop
and cloud solution, empowering you to work in the most efficient and cost-effective way.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | |
|