Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Text-to-speech script


  • Please log in to reply
19 replies to this topic
Landvermesser
  • Members
  • 51 posts
  • Last active: Aug 12 2008 09:02 AM
  • Joined: 03 Nov 2004
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.

#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"

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


Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005
Is there any way to let the speaker talk with german artificial?

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

Thalon

savage
  • Members
  • 207 posts
  • Last active: Jul 03 2008 03:12 AM
  • Joined: 02 Jul 2004
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.

Landvermesser
  • Members
  • 51 posts
  • Last active: Aug 12 2008 09:02 AM
  • Joined: 03 Nov 2004
Find the other languages here: http://www.text-read...eechengines.htm

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...

Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005
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
---------------------------

Landvermesser
  • Members
  • 51 posts
  • Last active: Aug 12 2008 09:02 AM
  • Joined: 03 Nov 2004
Sorry, at me too it is impossible to set other language.

Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005
:cry:
But maybe it helps to train my english-linguation and my ability to understand spoken english!

Thx,
Thalon

Rumbah
  • Members
  • 13 posts
  • Last active: Aug 04 2010 03:18 AM
  • Joined: 30 Mar 2005
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.

Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005
Thx!
I'll try it!

Thalon

starms
  • Guests
  • Last active:
  • Joined: --
A more efficient way of doing this is: -

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


AHKnow*
  • Guests
  • Last active:
  • Joined: --
Great script!

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
Very cool idea!

I've come up with an even more efficient way (I think):
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):
#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


elizas
  • Guests
  • Last active:
  • Joined: --
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.mindfires...-in-vbs-794.php

vla
  • Members
  • 48 posts
  • Last active: Apr 03 2014 05:58 AM
  • Joined: 12 May 2007
I keep getting a confirm message about allowing IE to use my clipboard. Any way around this? (btw love the program!)

ebpdoug
  • Members
  • 24 posts
  • Last active: Oct 19 2013 09:50 PM
  • Joined: 28 Oct 2009
Elizas' VBScript (or any of the other VBScripts) can have the text to be spoken passed as a command line argument:

'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):
;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.micro...y/ee156618.aspx