Larz
3/29/2008 12:08:00 PM
I have this program, it just runs and anytime the clipboard changes
and contains some large size,
it run the speech thing through win-sapi. So I can go to any website,
highlight some text and copy it to the clipboard and it will speak the
text. I can't get it to interupt very well. If you hit control-c it
won't
stop until it's done with the text, thus I broke it into lines.
Here's my current problem:
I would like to be able to read raw keyboard data, so that if I hit
spacebar or some function key, it would pause, even if the dos shell
running the program was not in focus. How can I do that ?
-----------------------------------------------------
require 'win32/clipboard'
include Win32
require 'win32ole'
class MySpeech
def initialize
@obj_voice = WIN32OLE.new("SAPI.SpVoice")
@obj_get_voices = @obj_voice.GetVoices
@obj_get_voices.each { |voice| puts voice.GetDescription }
end
def talk(txt)
done = false
lines = txt.split(/$/)
lines.each do |ln|
@obj_voice.speak ln
end
end
def run
prev = Clipboard.data
while true
curr = Clipboard.data
if curr and curr != prev and curr.length > 80
talk curr
prev = curr
end
end
end
end
spkthr = Thread.new do
spk = MySpeech.new
spk.run
end
spkthr.join