I'm not very familiar with using the ClipboardData object.
I try to avoid it because it doesn't work in IE4. When I
try your code and add a pause loop for IE to finish
navigating it works without error, but I'm not returning
any text from the Clipboard!
Set IE = WScript.CreateObject("InternetExplorer.Application")
IE.navigate "about:blank"
Do Until IE.ReadyState = 4
Loop
s1 = IE.document.parentWindow.ClipboardData.getData("Text")
I copied that exactly from some other code I have that works.
The only thing I can think of is that maybe it's a security
problem when the call is not coming from the scope of the
IE document.
The following also works but I don't seem to get
any text from the Clipboard in this sample either:
Dim ObH
Set ObH = CreateObject("htmlfile")
s = ObH.ParentWindow.ClipboardData.GetData("Text")
MsgBox s
I don't know of any other way to get Clipboard text
outside of a 3rd-party component, but you might try
doing it from within an IE page.
I think it's best to separate the problems. If you
don't test your functions separately then
you can't find the problem. That's why I tested with
a plain string for the speech problem, instead of
involving IE. IE is a separate issue.
If you try the code I posted you'll see that it works.
Two points:
1) Reread the explanation I gave you of how the flags
work. (Sorry that wasn't more clear.) Your second new
sample is using the purge flag without the async flag.
Why would you expect that to work?
2) Your first new sample has the "SPF_ASYNC = 1"
commented out. So you're still not using the async flag.
You need to either declare constants and use them,
or use numbers.
You have three samples but you haven't yet tested the
async flag in any of them. Why not just use Speak text, 3
instead of fiddling with the constants?
Personally I don't see the point of using constants that
are not in WSH because you need to know their value
anyway, so they don't provide any convenience. Constants
are used a lot in C++ but they're already declared elswhere,
so it makes sense to use them. In VBS they're just the
same as variables unless they're part of WSH. For instance,
you don't need to know the characters in vbCrLf
in order to use it, but when you declare a constant in your
code like Const SPF_ASYNC = 1 that's the same as a variable.
(In fact, in your code you *did* declare them as variables.)
You can't use SPF_ASYNC unless you declare it and
already kow its value, so what's the point?
It's up to you, but if you want to use constants then you
need to make sure they're declared properly. Since
SPF_ASYNC = 1 is commented out in your sample,
you're actually sending 0 on that call.
Post by vmarsAlso, in your code, how are you passing it the filename?
File name? There is no file involved. I just
built a string of 1,000 copies of the word "okay"
and had it read that.
--
--
Post by vmarsThis is my entire original code, in a file called 'SpeakClipBoard.vbs' .
Works great!
Set ISpeechVoice = CreateObject("SAPI.SpVoice")
'read from clipboard
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
ISpeechVoice.Speak
oIE.document.parentWindow.clipboarddata.getData("text"), SPF_DEFAULT
Set oIE = Nothing
Set ISpeechVoice = CreateObject("SAPI.SpVoice")
'read from clipboard
'SPF_ASYNC = 1
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
ISpeechVoice.Speak
oIE.document.parentWindow.clipboarddata.getData("text"), SPF_ASYNC
Set oIE = Nothing
This is my entire code, in a file called 'PurgeBeforeSpeakClipBoard.vbs' .
Set ISpeechVoice = CreateObject("SAPI.SpVoice")
'read from clipboard
SPF_PURGEBEFORESPEAK = 2
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
ISpeechVoice.Speak
oIE.document.parentWindow.clipboarddata.getData("text"),
SPF_PURGEBEFORESPEAK
Set oIE = Nothing
Could you try them on your system and see if they work?
Is there a better way to get to the ClipBoard than using
"InternetExplorer.Application"?
Also, in your code, how are you passing it the filename?
Thanks!
--
ô¿ô
V e r n www.parentpresent.org
NoWorrys = KidSafe Internet Filter (Freeware)
Post by mayayanaIt would help if you post your code. You're using
constants for the flags but it's not clear whether
you declared them. Also, in your sample below, you
didn't use ASync, only the purge flag.
The following sample works fine for me.
It creates a string of 1,000 "okay ", then reads it,
waits two seconds, and quits. It works as expected,
with the voice reading 5 or 6 OKs and then quitting.
Dim V, s1, i
Set V = CreateObject("Sapi.SpVoice")
For i = 1 to 1000
s = s & "okay "
Next
V.speak s, 3
WScript.sleep 2000
V.speak " ", 3
MsgBox "done"
Set V = Nothing
--
--
Post by vmarsThanks in advance!
When i fire off the script with ('SPF_ASYNC' or) 'SPF_PURGEBEFORESPEAK'
It speaks the text.
Line 6
Char 6
Error 0x80045006
Code 80045006
Source (null)
The same thing happens whether i 1st fire off with 'SPF_ASYNC' or
'SPF_DEFAULT', then 'SPF_PURGEBEFORESPEAK' .
Bottom line, so far, there seems to be no way to stop speaking once it
starts.
Anyone have ideas?
Set ISpeechVoice = CreateObject("SAPI.SpVoice")
'read from clipboard
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
ISpeechVoice.Speak
oIE.document.parentWindow.clipboarddata.getData("text"),
SPF_PURGEBEFORESPEAK
Set oIE = Nothing
--
ô¿ô
V e r n www.parentpresent.org
NoWorrys = KidSafe Internet Filter (Freeware)
Post by mayayanaYou're using 0 for the second parameter. I think that
if you use 2, with an empty string, it will stop. But you
may also need to use 1 on the first call.
SPF_DEFAULT = 0
SPF_ASYNC = 1
SPF_PURGEBEFORESPEAK = 2
SPF_IS_FILENAME = 3
SPF_IS_XML = 4
SPF_IS_NOT_XML = 5
SPF_PERSIST_XML = 6
The text to be spoken apparently gets put into a buffer.
For most uses it makes sense to use Speak sText, 1
or Speak sText, 3 because that allows you to switch
mid-stream.
In other words, if you
have it speaking a file and halfway through you want to
tell it to speak a different file, then the default flag will cause
it to finish speaking the first file before starting the second.
If the speech is tied to events that gets very confusing.
A flag of 1 (ASync), on the other hand, will cause it to switch
to the new text immediately. A flag of 2 causes it to dump
the buffer before starting the new call. So if you add them
together for a flag of 3 then each call will dump the buffer
Speak sText, 3
So Speak sText, 1 or Speak sText, 3 is probably required
in the *first* call in order to be able to stop it once started.
Then for the actual stop call I think that either Speak "", 2 or
Speak "", 3 should work.
(I always just use a flag of 3 for all calls, but I suppose
there may be cases where you want to hold the old text
buffer. Looking at some VB code I see that I also
used SPF_IS_NOT_XML, which is Speak sText, 8.
But I can't remember why I used that. The help just says
it means "The input text will not be parsed for XML markup. "
Also, if you don't already have it, you might want to get the
SAPI 5 SDK and install it. The SDK has good docs and lots
of samples.
--
--
Post by vmarsThanks in advance!
I am using a text-to-speech vbs script (below) that works great.
But sometimes it would be useful to stop, before finishing speaking the
entire clipBoard.
So how can i stop it in mid sentence, so to speak?
I could probably just kill the wscript.exe [PostMessage(AppHandle,
WM_QUIT,
Post by vmars0, 0)], but would rather do it with a script..
Set ISpeechVoice = CreateObject("SAPI.SpVoice")
'read from clipboard
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
ISpeechVoice.Speak
oIE.document.parentWindow.clipboarddata.getData("text"), SPF_DEFAULT
Set oIE = Nothing
--
ô¿ô
V e r n www.parentpresent.org
NoWorrys = KidSafe Internet Filter (Freeware)