Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Speak selected text; Use hot keys to control it.
#1
This macro speaks selected text. You can control it with hotkeys.
Requires QM 2.3.2 or later.

How to use:
Select one or more sentences of text in web browser or other app.
Press Ctrl+Shift+S and listen.
The thread ends when it ends to speak the text. Or when you press End key. While running, shows tray icon.

Function SpeakSelection
Trigger CSs \DREAMWEAVER     Help - how to add the trigger to the macro
Code:
Copy      Help
;Speaks selected text.

;How to use: Select text and press Ctrl+Shift+S.
;You can use hot keys to control it. Shows them when called first time.

str s.getsel
SpeakTextWithHotKeys s -1

This is similar, but uses OCR to get text.

Function SpeakSelectionOCR
Trigger CAs \DREAMWEAVER     Help - how to add the trigger to the macro
Code:
Copy      Help
;Speaks selected text using OCR. Use this macro for text that cannot be normally selected, eg in some pdf documents.
;Requires MS Office. Uses Office's MODI component. If it is not installed, should install automatically.

;How to use: Press Ctrl+Alt+S and select text. To select text, draw rectangle with mouse.
;You can use hot keys to control it. Shows them when called first time.

;________________________

;Capture image.

str f.expandpath("$temp$\speak_ocr.bmp")
RECT r
if(!CaptureImageOrColor(0 16|32 0 f r)) ret
OnScreenRect 1 &r

;OCR.

typelib MODI {A5EDEDF4-2BBC-45F3-822B-E60C278A1A79} 11.0

MODI.Document doc._create
doc.Create(f) ;;load the file

doc.OCR(MODI.miLANG_ENGLISH -1 0); err OnScreenDisplay "OCR failed."; ret

MODI.Image im=doc.Images.Item(0) ;;first page
str s=im.Layout.Text

;Results.

SpeakTextWithHotKeys s -1
OnScreenRect 2 &r

Also need this function.

Function SpeakTextWithHotKeys
Code:
Copy      Help
;/
function $text [rate] ;;rate: -10 to 10.

;Speaks text.
;You can use hot keys to control it. Shows them when called first time.


AddTrayIcon "sound.ico"

int+ __speak_sel_info2
str si=
;Hot keys:
;
;Left - repeat current sentence.
;Right - next sentence.
;Up - previous sentence.
;Down - pause/resume.
;End - end.
;Home - restart.
if(!__speak_sel_info2) __speak_sel_info2=1; mes si "" "i"

str s=text
if(!s.len) ret
s.findreplace("..." ".")
int paused

typelib __SpeechLib {C866CA3A-32F7-11D2-9602-00C04F8EE628} 5.0

__SpeechLib.SpVoice spv._create

spv.Rate=rate
if(_winnt>=6) waveOutSetVolume 0 0xffffffff ;;on Vista, this sets max wave out volume for qm only, because may be 0 initially

spv.Speak(s 1)

__RegisterHotKey k
k.Register(0 1 0 VK_LEFT)
k.Register(0 2 0 VK_RIGHT)
k.Register(0 3 0 VK_UP)
k.Register(0 4 0 VK_DOWN)
k.Register(0 5 0 VK_END)
k.Register(0 6 0 VK_HOME)
SetTimer(0 1 100 0)

MSG m
rep
,if(GetMessage(&m 0 0 0)<1) break
,
,sel m.message
,,case WM_HOTKEY
,,err-
,,if(paused and m.wParam<=3) paused=0; spv.Resume
,,sel m.wParam
,,,case 1 spv.Skip("Sentence" 0)
,,,case 2 spv.Skip("Sentence" 1)
,,,case 3 spv.Skip("Sentence" -1)
,,,case 4 paused^1; if(paused) spv.Pause; else spv.Resume
,,,case 5 break
,,,case 6 spv.Speak(s 3)
,,err+ bee
,,
,,case WM_TIMER
,,if(spv.Status.RunningState=SRSEDone) break


Forum Jump:


Users browsing this thread: 1 Guest(s)