AutoHotkey Community

It is currently May 27th, 2012, 11:28 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Text-to-speech script
PostPosted: August 6th, 2005, 12:01 pm 
Offline

Joined: November 3rd, 2004, 11:24 am
Posts: 51
A simple script which speaks the selected text with artificial voice. The script creates temporary VBScript and hidden IE window. Uses Microsoft Speech API and any Speech Engine registered in the Windows Registry. If you use Windows 2000/XP, most likely, your system already has the necessary components.

Code:
#F12::
SpeakingSelected:
   FileDelete, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, Set ISpeechVoice `= CreateObject`(`"SAPI.SpVoice`"`)`n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, Set oIE `= WScript.CreateObject`(`"InternetExplorer.Application`"`)`n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, oIE.navigate `"about`:blank`"`n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, ISpeechVoice.Speak oIE.document.parentWindow.clipboarddata.getData`(`"text`"`)`, SPF_DEFAULT`n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, Set oIE = Nothing, %A_ScriptDir%\SpeechMe.vbs
   ClipSaved =
   ClipSaved := ClipboardAll
   Clipboard =
   Send, ^c
   ClipWait, 1
   Clipboard = %Clipboard%
   If Clipboard =
      {
         Clipboard = The text to speech not found! Please select some text and retry.
      }
   Run, WSCRIPT.EXE "%A_ScriptDir%\SpeechMe.vbs",,, WSCRIPT_PID
   SetTimer, Wait5sec, 5000
   Return
   
Wait5sec:
   FileDelete, %A_ScriptDir%\SpeechMe.vbs
   Clipboard := ClipSaved
   SetTimer, Wait5sec, Off
   Return

#F11::   
StopSpeaking:
   Process, Close, %WSCRIPT_PID%
   DetectHiddenWindows, On
   SetTitleMatchMode, 2
   WinClose, about`:blank
   SetTitleMatchMode, 3
   DetectHiddenWindows, Off
   Return


For info only: the file "SpeechMe.vbs"

Code:
Set ISpeechVoice = CreateObject("SAPI.SpVoice")
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
ISpeechVoice.Speak oIE.document.parentWindow.clipboarddata.getData("text"), SPF_DEFAULT
Set oIE = Nothing


Last edited by Landvermesser on August 7th, 2005, 5:23 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2005, 10:40 pm 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
Is there any way to let the speaker talk with german artificial?

But, also this way it is a great script! :wink:

Thalon


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2005, 11:19 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
Why are you using the hidden IE window? Seems like unnecessary overhead.

Thalon, there's voices for other languages available, but I haven't looked around enough to know where they are.

_________________
<enormous animated gif>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2005, 5:22 pm 
Offline

Joined: November 3rd, 2004, 11:24 am
Posts: 51
Find the other languages here: http://www.text-reader.com/trspeaker_English/speechengines.htm

Quote:
Why are you using the hidden IE window? Seems like unnecessary overhead.


I can not finding any other VBScript (or any other) without this IE window. I have the C++ code to this, but it is 1 MB exe...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2005, 8:14 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
I have downloaded and installed 'AgtX0407.exe' (German Setup), but it's still english.
Where am I wrong?

Thx,
Thalon

Edit:
After rebooting it is not running any more:
---------------------------
Windows Script Host
---------------------------
Skript: E:\Scripts\SpeechMe.vbs
Zeile: 4
Zeichen: 1
Fehler: Typen unverträglich: 'ISpeechVoice.Speak'
Code: 800A000D
Quelle: Laufzeitfehler in Microsoft VBScript

---------------------------
OK
---------------------------


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2005, 9:14 am 
Offline

Joined: November 3rd, 2004, 11:24 am
Posts: 51
Sorry, at me too it is impossible to set other language.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2005, 11:54 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
:cry:
But maybe it helps to train my english-linguation and my ability to understand spoken english!

Thx,
Thalon


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2005, 1:01 pm 
Offline

Joined: March 30th, 2005, 2:00 pm
Posts: 13
If you use WinXP you first have to install an update to the SAPI. WinXP comes with version 5.0 that does not support German. You can donwload SAPI 5.1 from the Microsoft homepage, then the German language should work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2005, 4:25 pm 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
Thx!
I'll try it!

Thalon


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2005, 7:52 pm 
A more efficient way of doing this is: -

Code:
Talk:
   FileDelete, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, Dim voic `n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, Set voic = WScript.CreateObject("SAPI.SpVoice")`n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, Set voic.voice = voic.GetVoices("", "Language=809").Item(0)`n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, voic.Speak("%Say%")`n, %A_ScriptDir%\SpeechMe.vbs
   FileAppend, Set voic = nothing`n, %A_ScriptDir%\SpeechMe.vbs
   Run, WSCRIPT.EXE "%A_ScriptDir%\SpeechMe.vbs",,, WSCRIPT_PID
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2005, 7:00 am 
Great script!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2006, 3:54 pm 
Offline

Joined: October 10th, 2005, 10:44 am
Posts: 299
Location: Germany
Very cool idea!

I've come up with an even more efficient way (I think):
Code:
say(string)
{
   FileAppend,
      ( LTRim
         Dim voic
         Set voic = WScript.CreateObject("SAPI.SpVoice")
         Set voic.voice = voic.GetVoices("", "Language=809").Item(0)
         voic.Speak("%string%")
         Set voic = nothing
      ), %A_ScriptDir%\timeAnnounce.vbs
   RunWait, WSCRIPT.EXE "%A_ScriptDir%\timeAnnounce.vbs",,, WSCRIPT_PID
   FileDelete, %A_ScriptDir%\timeAnnounce.vbs
}

Too bad this ain't possible directly from AHK yet (or is it?)...

FYI: The VBS file is called timeAnnounce because I use it in a script that tells me the current time (e.g. when playing games in fullscreen mode, I have one of my keyboard's media keys start this script):
Code:
#NoTrayIcon

FormatTime, currentHour, %A_Now%, H
FormatTime, currentMinute, %A_Now%, m
FormatTime, currentSecond, %A_Now%, s
currentTime = %currentHour% %currentMinute%
timeString = time is %currentTime%
say(timeString)
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Text-To-Speech in VBS
PostPosted: January 27th, 2010, 1:01 pm 
This tip demonstrates how to use SAPI for Text-To-Speech capability in VB Script

BlankDim message,sapi
message=InputBox("Write something in textbox","Hemant :)")
set sapi = CreateObject("sapi.spvoice")
sapi.Speak message

copy this code to notepad and save it .vbs extension(for e.g. hemant.vbs)



After making a vbs file just double click on that file and type anything you want in the textbox, click ok and listen.

thanks
Eliza
http://www.mindfiresolutions.com/texttospeech-in-vbs-794.php


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2010, 3:21 am 
Offline

Joined: May 12th, 2007, 8:29 am
Posts: 48
I keep getting a confirm message about allowing IE to use my clipboard. Any way around this? (btw love the program!)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 7th, 2010, 2:46 pm 
Offline

Joined: October 28th, 2009, 3:56 am
Posts: 22
Elizas' VBScript (or any of the other VBScripts) can have the text to be spoken passed as a command line argument:

Code:
'VBScript to be named SPEAK.vbs
Dim sapi 'not really necessary
set sapi = CreateObject("sapi.spvoice")
sapi.Speak WScript.Arguments.Item(0)

This would be called (or RUN from AHK) thus (SPEAK.vbs may need full path specification):
Code:
;AutoHotkey calling method:
TextToSay = "This text will be spoken by the V B script speak dot v b s. This can be a very long string."
;note quotation marks around the string
RUN cscript "[path\]speak.vbs" %TextToSay%
command line arguments:
http://technet.microsoft.com/en-us/library/ee156618.aspx


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, MSN [Bot], nomissenrojb, nothing and 68 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group