I’ve been toying around with text to speech in scripts both in VBScript and PowerShell. I thought I’d share some thoughts and techniques for working with these objects. I’m still trying to find a truly practical need for this in an administrative script, but this is interesting technology to kick around.
The primary object you will need to create is SAPI.SPVoice. More than likely you won’t need to do much more than this to get started:
Set objSPVoice=CreateObject(“SAPI.SpVoice”)
objSPVoice.Speak “Hello, world.”
It’s really that simple. By default, most XP systems have a single voice installed calledMicrosoft Sam, but if you download and install the Microsoft Speech SDKyou can install some additional voices like Microsoft Mary andMicrosoft Mike. If you do that, you can run this script to hear the different voices.
Dim objSPVoice,colVoices
Set objSPVoice=CreateObject(“SAPI.SpVoice”)
Set colVoices=objSPVoice.GetVoices()
WScript.Echo colVoices.Count
For x=0 To colVoices.Count-1
Set objSPVoice.Voice=objSPVoice.GetVoices.Item(x)
objSPVoice.speak “item ” & x & “, equals ” & objSPVoice.Voice.GetDescription
objSPVoice.Speak “To be, or not to be. That, is the question.”
Next
Again, you don’t need to specify a voice unless you have more than one installed.