Text-To-Speech in AutoHotkey v1.1+ is fairly simple. If you just want to speak one thing, you can do it in one line. For example:
ComObjCreate("SAPI.SpVoice").Speak("Peter Piper picked a peck of pickled peppers")However, it you want to do anything more complicated, you'll need to add a few more lines of code.
A few Text-To-Speech examples for AutoHotkey v1.1+ have already been published (see the References section below). I decided to update the Text-To-Speech via COM - Examples post that I wrote a few years back because it includes a few advanced features that I haven't seen anyone use yet.
There are currently three example scripts:
- Single Instance. This script attempts to duplicate most of the functionality of the TTSApp demo that is provided with the Microsoft Speech SDK 5.1. See the Issues/Considerations section for additional information.
- Multiple Instances. This script demonstrates the use of multiple SpVoice instances.
- Wait Until Done. This script demonstrates a number of techniques for monitoring the end of a SpVoice stream.
The pertinent files are included in this archive:
- TTS Examples for AutoHotkey_L.zip (Includes source, icons, and example files)
The Microsoft Speech SDK 5.1 must be installed if using any Windows version earlier than Windows XP. See the References section for more information.
A few considerations:
- Limited Testing. Although these scripts should work on most Windows versions (Windows 98+), I was only able to test using Windows XP. In addition, I only have one audio output (my sound card), so I was unable to test using an alternate audio output.
- Animation. The Example1GUI script includes animation. Although the animation is fairly accurate, I was unable to completely remove the flickering. It's annoying, I know. Live with it. The animation does not work on Windows 98 because the OS does not support transparent icons. Sorry 'bout that.
- Microsoft Speech SDK 5.1
This software is not necessary if using Windows XP or greater. However, the installation includes two additional voices (Microsoft Mike and Microsoft Mary) so it might be worth the trouble to install it.
The example scripts may dump useful information to a debugger. DebugView is not the only debug viewer out there but it's my favorite.
SpVoice Interface (SAPI 5.3)
A must-have guide to the SpVoice (Text-To-Speech engine) interface. This guide includes a list of all of the SpVoice methods as well as what is needed to call them.
SpVoice (Events) Interface (SAPI 5.3)
A must-have guide to the SpVoice Events interface. This guide includes a list of all the SpVoice events as well as all of the parameters that are passed for each event.
COM Object Reference [AutoHotkey_L] - COM Object: SAPI.SpVoice
Example of how to use the SAPI.SpVoice COM object in AutoHotkey_L.
[Function] Easy Text To Speech
AutoHotkey function to speak text and control the Text-To-Speech engine.
I'm still a AutoHotkey v1.1+ beginner. If I've made any logic or code blunders (major or minor), I'm hoping that someone will be kind enough to bring it to my attention. I hope to benefit from your experience.
I hope that someone can make use of this information.