<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Using Windows Text to Speech with Delphi

Published on
16,124 Points
9,124 Views
Last Modified:
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech.

SAPI Installation
First you need to install the SAPI type library, the type library is attached to this tutorial, into Delphi.

In the Delphi IDE install a new component via the menu:
Component > Install Component...   (See Step 1 Image)
Step 1 Image

Select the 'Into new package' Tab, then click on the 'Browse' button, Select the '.PAS' file included in the type library attachment.   (See Step 2 Image)
Step 2 Image
Create a new package file name such as 'Speech.dpk'. Enter a package description such as 'Windows Speech API'. (See Step 2 Image)

Click on 'OK', when prompted to build then install the package, click on the 'Yes' button. (See Step 3 Image)
Step 3 Image
You should get a prompt saying that new components have been installed. (See Step 4 Image)
Step 4 Image
Simple Text To Speech
Create a new application.

Find the 'SpVoice' component, and drag it onto your form. (See Step 5 Image)
Step 5 Image
Add an edit box and a button to the form and, on the button onclick event handler, enter the following code:

procedure TForm1.Button1Click(Sender: TObject);
begin
if not (Edit1.Text = '') then
SpVoice1.Speak(Edit1.Text, SVSFDefault);
end;

Open in new window


When the user enters something into the textbox the SAPI says the text outloud. (See Step 6 Image).
Step 6 Image

Change Voice Speed

Add a TrackBar component to your form (TrackBar is found in the win32 pallette). On the trackbar onchange event handler add the code below:

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
SpVoice1.Rate := TrackBar1.Position;
end;

Open in new window


This trackbar will change the speed of the text to speech engine depending on where the trackbar is. It will make the voice either slower or faster; this may help the user understand the speech.

Run the project and you have a simple text to speech implementation in Delphi. This could be used to enable your application to speak to the user.

I have attached the project files so you can use them for reference.

The tyle libraries cannot be attached, however they are here:

http://rapidshare.com/files/416314381/Speech_Type_Library.zip.html
speech-tutorial.zip
0
Comment
Author:flexiwebsw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Expert Comment

by:Eric AKA Netminder
flexiwebsw,

Congratulations! Your article has been published.

ericpete
Page Editor
0
 

Expert Comment

by:fdecker
How do you set the input for speech recognition? spMMAudioIn1.DeviceID := my_integer gives an error. This worked in SAPI 5.1. I am using SAPI 5.4.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month