Jump to content

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

Text-To-Speech Examples for AutoHotkey v1.1+


  • Please log in to reply
6 replies to this topic
jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
Introduction
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.

Examples
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.
Screenshots
Example1GUI_01.jpg
Example2GUI_01.jpg
Example3GUI_01.jpg

The Code
The pertinent files are included in this archive:Requirements
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.

Issues/Considerations
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.
References
  • 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.
    http://tinyurl.com/yptaoo

    DebugView
    The example scripts may dump useful information to a debugger. DebugView is not the only debug viewer out there but it's my favorite.
    http://technet.micro...s/bb896647.aspx

    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.
    http://tinyurl.com/mqngf4

    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.
    http://tinyurl.com/lsjq48

    COM Object Reference [AutoHotkey_L] - COM Object: SAPI.SpVoice
    Example of how to use the SAPI.SpVoice COM object in AutoHotkey_L.
    http://www.autohotke...p=391483#391483

    [Function] Easy Text To Speech
    AutoHotkey function to speak text and control the Text-To-Speech engine.
    http://www.autohotke...p=391538#391538
Final Thoughts
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.

---------------------------------------------------------------------------
Release Notes

v0.1
Original release.


kenn
  • Members
  • 407 posts
  • Last active: Jan 14 2015 08:16 PM
  • Joined: 11 Oct 2010
Great! I was looking for its AHK_L version. I would make an RSS reader with speech engine. Thank you.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Impressive! :D

I suggest to include a no-GUI version to make it easier to find the relevant TTS code.

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005

I suggest to include a no-GUI version to make it easier to find the relevant TTS code.

A couple of thoughts...

Although the Example1GUI script is certainly not ideal for someone who wants to use Text-To-Speech in a linear and/or non-interactive fashion, it was designed so that a developer can easily find the code that is pertinent to what he/she needs. For example, to change the rate, look for the Rate routine. To set or change the voice, look for the Voice routine. And so on.

Also, the "Easy Text To Speech" function by Learning one has a good break down of Text-To-Speech requirements (what the developer might want to do) and an example of how to do it. See the References section in the first post for the link.

I hope this helps. Thank you for your feedback.

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011
Just found this in PHP COM and was wondering if implemented for _L yet :D.
;php
$voice = new COM("SAPI.SpVoice");
$voice->Speak("Hello, lets have a conversation");
Nice job jballi

ericitaquera
  • Members
  • 2 posts
  • Last active: Mar 31 2011 02:05 PM
  • Joined: 31 Mar 2011
Does someone know a way to alternate between more than one voice. Example: Use Mike´s voice in one line and Anna´s in other?

Thx!

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005

Does someone know a way to alternate between more than one voice. Example: Use Mike´s voice in one line and Anna´s in other?

This can be be done manually by doing exactly you described: Set the voice to Mike, speak the first line. Set the voice to Anna, speak the 2nd line. An so on.

A better solution might be to speak using a SAPI XML file which is an XML file with tags that instruct the TTS engine what to do. An example has been included with this project. Run the first example (Example1GUI.ahk), click on the "Open file..." button, go to the "Example Files" folder, and then select the "TTSXmlDemo.xml" file. You can speak this file by clicking on the "Play" button.

I hope this helps. An XML TTS Tutorial can be found here:
http://msdn.microsof...7(v=vs.85).aspx

Good luck!