ToyleY Posted December 22, 2007 Posted December 22, 2007 (edited) Text-to-speech Gizmo Reads clipboard with hot keys to start/pause/stop expandcollapse popup#cs -------------------------------------------------- 'Tray Speak' ============ - Speaks whatever is on the clipboard using the Microsoft SAPI 5.1 speech engine (the Windows XP native SAPI). By ToyleY 20 December 2007 ver 1.01 using AutoIt v3.2.10.0 released (25th November, 2007) Instructions ------------ Use ordinary Windows methods to copy to clipboard (highlight text then ctrl+c etc.) Set voice and speech rate in Windows control Panel. Run the prog and it installs a tray icon 1. Ctrl-Alt-p toggle for speaking / pause speaking 2. Ctrl-Alt-s stop the speach engine click on tray icon for menu 'About/Exit/Instructions' Notes ===== Copy anything to the clipboard for reading - forum posts, contents of files, documents, Web pages etc. Program does not fall over if non-text on clipboard or clipboard empty. Uses very little resouces so can make it run on startup as a useful tool always available. Get extra SAPI 5.1 Voices here (Mike and Mary) http://www.st-tools.com/download/sapi5xp-addvoices.msi #ce --------------------------------------------------- #include <GUIConstants.au3> #NoTrayIcon ; opts for TrayCreateItem Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $o_speech = ObjCreate("SAPI.SpVoice") ; create the speech engine object $plyF = 0 ; flag to indicate - speaking = 2 / pauses speaking = 1/ not speaking or end of stream = 0 $AbFlag = 1 ; flag for 'about' text changes $ClipB = "" ; var to hold contents of the clipboard HotKeySet("^!p", "CBS_Talk_Pause") ; Ctrl-Alt-p toggle for speaking / pause speaking HotKeySet("^!s", "CBS_Stop") ; Ctrl-Alt-s stop the speech engine $institem = TrayCreateItem("Instructions") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() ;show the tray icon TraySetToolTip("<<< Yabber! >>>" & @CRLF & " Text-to-Speach" & @CRLF & ""& @CRLF & " Click for Menu") ; sets the tray tool tip (on mouse over) While 1 sleep(10) $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $institem InstR() Case $msg = $aboutitem AboutR() Case $msg = $exititem CBS_Stop() ; shut down speech engine HotKeySet("^!p") ; unregister this hotkey combination HotKeySet("^!s") Exit EndSelect WEnd Func CBS_Talk_Pause() if $plyF = 0 then $ClipB = ClipGet() If ($ClipB = "") OR ($ClipB = " ") then ; only test for null or single space to decide if clipboard is emplty $o_speech.Speak ("The clipboard is empty. There is nothing to say. Please copy to the clipboard using control see.",1) else $o_speech.Speak (ClipGet(),1) $plyF = 2 ; set the program flag to indicate speech engine is running EndIf else $w = $o_speech.Status ; find out the running status Select Case $w.RunningState = 0 ; speech engine is paused $o_speech.Resume () ; resume the speech engine $plyF = 2 ; set the program flag to indicate speech engine is running Case $w.RunningState = 1 ; speech engine has finished stream - restart ; shut down speech engine ; shut down speech engine $ClipB = ClipGet() ; user might have copied a null value while original was speaking If $ClipB = "" then ; is the clipboard empty $plyF = 0 ; set the program flag to indicate speech engine not running else $o_speech.Speak($ClipB,1) $plyF = 2 ; set the program flag to indicate speech engine running Endif Case $w.RunningState = 2 ; speech engine is running $o_speech.Pause () ; pause the speech engine $plyF = 1 ; set the program flag to indicate speech engine is paused Case Else ; catch any error condition and shut down speech engine CBS_Stop() ; shut down speech engine $plyF = 0 ; set the program flag to indicate speech engine not running EndSelect Endif EndFunc Func CBS_Stop() if $plyF > 0 then $o_speech = ObjCreate("SAPI.SpVoice") $plyF = 0 Endif EndFunc Func AboutR() $GUI_About = GUICreate(" <<< ABOUT >>>", 230, 175, 100, 100, $DS_MODALFRAME) GUISetState () $Abt1Y1 = GuiCtrlCreateLabel("Y", 84, 10, 8, 25) $Abt1Y2 = GuiCtrlCreateLabel("a", 92, 10, 8, 25) $Abt1Y3 = GuiCtrlCreateLabel("b", 100, 10, 8, 25) $Abt1Y4 = GuiCtrlCreateLabel("b", 108, 10, 8, 25) $Abt1Y5 = GuiCtrlCreateLabel("e", 116, 10, 8, 25) $Abt1Y6 = GuiCtrlCreateLabel("r", 124, 10, 8, 25) $Abt1Y7 = GuiCtrlCreateLabel("!", 130, 10, 8, 25) ; format text size GUICtrlSetFont ($Abt1Y1, 9, 600) GUICtrlSetFont ($Abt1Y2, 9, 600) GUICtrlSetFont ($Abt1Y3, 9, 600) GUICtrlSetFont ($Abt1Y4, 9, 600) GUICtrlSetFont ($Abt1Y5, 9, 600) GUICtrlSetFont ($Abt1Y6, 9, 600) GUICtrlSetFont ($Abt1Y7, 9, 600) ; format text colour GUICtrlSetColor($Abt1Y1,0x006600) GUICtrlSetColor($Abt1Y2,0xcc0099) GUICtrlSetColor($Abt1Y3,0x006600) GUICtrlSetColor($Abt1Y4,0xcc0099) GUICtrlSetColor($Abt1Y5,0x006600) GUICtrlSetColor($Abt1Y6,0xcc0099) GUICtrlSetColor($Abt1Y7,0x006600) ; create other static text $Abt2 = GuiCtrlCreateLabel("Ver 1.01 - December 20 2007", 20, 40, 200, 25) $Abt3 = GuiCtrlCreateLabel("Text-to-Speech gizmo ", 40, 55, 200, 25) $Abt4 = GuiCtrlCreateLabel("Designed and written by", 22, 75, 250, 25) $Abt5 = GuiCtrlCreateLabel("ToY", 180, 75, 30, 25) ; size of text GUICtrlSetFont ($Abt2, 9, 600) GUICtrlSetFont ($Abt3, 9, 600) GUICtrlSetFont ($Abt4, 9, 600) GUICtrlSetFont ($Abt5, 9, 600) ; colour for text (my name) GUICtrlSetColor($Abt5,0x996699) ; create the close button $Abtn_Close = GUICtrlCreateButton("Close", 62, 110, 90, 25) GUICtrlSetFont ($Abtn_Close, 9, 600) ; centre the 'about' box on the users display WinMove($GUI_About, "", ((@DesktopWidth)/2) - 115, ((@DesktopHeight)/2) - 87) While 1 sleep(10) If $AbFlag = 1 Then ; format text colour - style 1 GUICtrlSetColor($Abt1Y1,0x006600) GUICtrlSetColor($Abt1Y2,0xcc0099) GUICtrlSetColor($Abt1Y3,0x006600) GUICtrlSetColor($Abt1Y4,0xcc0099) GUICtrlSetColor($Abt1Y5,0x006600) GUICtrlSetColor($Abt1Y6,0xcc0099) GUICtrlSetColor($Abt1Y7,0x006600) $AbFlag = 2 Else ; format text colour - style 2 GUICtrlSetColor($Abt1Y1,0xcc0099) GUICtrlSetColor($Abt1Y2,0x006600) GUICtrlSetColor($Abt1Y3,0xcc0099) GUICtrlSetColor($Abt1Y4,0x006600) GUICtrlSetColor($Abt1Y5,0xcc0099) GUICtrlSetColor($Abt1Y6,0x006600) GUICtrlSetColor($Abt1Y7,0xcc0099) $AbFlag = 1 Endif $msg = GUIGetMsg() If $msg = $Abtn_Close Then ExitLoop $msg = TrayGetMsg() ; need to catch tray messages in this loop If $msg = $exititem Then GUIDelete ($GUI_About) CBS_Stop() ; shut down speech engine HotKeySet("^!p") ; unregister this hotkey combination HotKeySet("^!s") Exit Endif Wend GUIDelete ($GUI_About) EndFunc Func InstR() $GUI_Inst = GUICreate(" <<< INFORMATION >>>", 437, 425, 292, 125, $DS_MODALFRAME) GUISetState () $Inst_close = GUICtrlCreateButton("Close", 165, 362, 90, 25) GUICtrlSetFont ($Inst_close, 9, 600) $xlist = GuiCtrlCreateList("", 15, 15, 400, 340, $LBS_NOSEL+$WS_VSCROLL) GuiCtrlSetData($xlist, "Usage:||1. Press the Ctrl+Alt+p keys together to toggle between | speaking and pause.||2. Press the Ctrl+Alt+s keys together to stop speaking. | Note that pressing Ctrl+Alt+p again will now start| reading the clipboard from the beginning.||3. Right or left mouse-click on the program tray icon to| bring up the menu. Selecting 'Instructions' brings up| this box. Selecting 'About' brings up the About box and| selecting 'Exit' closes the program.|||Put some other guff here about how it works", "") GUICtrlSetFont ($xlist, 9, 600) WinMove($GUI_Inst, "", ((@DesktopWidth)/2) - 215, ((@DesktopHeight)/2) - 187) While 1 sleep(10) $msg = GUIGetMsg() If $msg = $Inst_close Then ExitLoop $msg = TrayGetMsg() ; need to catch tray messages in this loop If $msg = $exititem Then GUIDelete ($GUI_Inst) CBS_Stop() ; shut down speech engine HotKeySet("^!p") ; unregister this hotkey combination HotKeySet("^!s") Endif Wend GUIDelete ($GUI_Inst) EndFunc Edited December 22, 2007 by ToyleY
zfisherdrums Posted December 22, 2007 Posted December 22, 2007 Hello ToyleY, Nice work! Merry Christmas, Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog...
zfisherdrums Posted December 22, 2007 Posted December 22, 2007 BTW: I updated Lazyreader2 to work with AutoIt 3.2.10. Thanks for the heads up. Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now