Search This Blog

Wednesday, March 03, 2010

VB script that speak ( something to read for you )

Peace be upon you

As sometimes I lose the focus and ability to read from the screen, sometimes I prefer listening to what I want to read, I use Mac most of the time and I really like the TTS support on it, it really feels very much like human, anyways, I liked to do so on Windows, I collected some code that can speak what's on the clipboard, so all you have to do, is put this code in file and put extension to file "VBS" , after that copy any text u like to hear and double click the vbs file, it will say the contents of the clipboard



Option Explicit

Const SVSFlagsAsync = 1
const SVSFPurgeBeforeSpeak = 2

Dim Speech
Dim FSO

CreateObjects
Main
DestroyObjects
Quit

Sub Main
Dim sText
Dim oIE
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
sText = oIE.document.parentWindow.clipboarddata.getData("text")
Set oIE = Nothing
'sText = InputBox("text", "Text2Speech")
sText = Trim(sText)
If sText <> "" Then
SpeakText sText
End If
End Sub

Sub SpeakText(sText)
On Error Resume Next
Speech.Speak sText, SVSFlagsAsync + SVSFPurgeBeforeSpeak
Do
Sleep 100
Loop Until Speech.WaitUntilDone(10)
End Sub

Sub StopSpeaking()
On Error Resume Next
Speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set Speech = Nothing
End Sub

Sub CreateObjects
Set Speech = CreateObject("SAPI.SpVoice")
Set FSO = CreateObject("Scripting.FileSystemObject")
End Sub

Sub DestroyObjects
Set Speech = Nothing
Set FSO = Nothing
End Sub

Sub Sleep(nTimeout)
WScript.Sleep nTimeout
End Sub

Sub Quit
WScript.Quit
End Sub


thanks for your time and I hope this trick is useful to you

BR
Ahmed Essam

No comments: