Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (26)


Speech Part 1 - How to Add "Text to Speech" (Speech Synthesis) to your Delphi AppsGo to Alec Bergamini's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Getting, Using and Installing the MS Speech SDK (SAPI 5.1)
Product:
Delphi 5.x (or higher)
Category:
Multimedia
Skill Level:
Scoring:
Last Update:
08/21/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet SAPI-5.1 spVoice Speak SAPI 5.1 Speech synthesis text-to-speech
Times Scored:
47
Visits:
24848
Uploader: Alec Bergamini
Company: O&A Productions
Reference: O&A Productions
 
Question/Problem/Abstract:
How can I get my application to read text?
Answer:



How to Add Speech Synthesis (a.k.a Text to Speech) to your Delphi Apps.

On Aug 11, 2001 Microsoft released the SAPI 5.1 SDK. This is significant because SAPI 5.1  is fully automated. That is you can use it from any language that supports OLE automation. These are not Active X controls and can be either early or late bound.

In this article I’m going to show you how to get and install the SAPI 5.1 SDK. Then I’m going to show how to use the SDK convert text to synthesized speech in a Delphi application. The synthesized speech is played over you computers speakers. I test this in Delphi 5 and 6.

To get SAPI 5.1 you need to go to Microsoft’s Speech.net Technologies web site at http://www.microsoft.com/speech/ and follow the link to the download. Right next to the download link is the release notes link. READ THE RELEASE NOTE! Especially if your development machine is using a default language other than US English.

If you are running a beta version of the XP operating system you might have some problems. This is because SAPI 5.1 is built into XP and the most recent public beta of XP as of this writing (RC 2) includes an earlier version of SAPI 5.1. Don’t try to install the release version of SAPI 5.1 into XP, it will not work.

Once you read the release notes follow the link to the Speech SDK 5.1 Download page. In most cases all you need to download is the link labeled “Speech SDK 5.1 (68 MB). This contains the SDK, the documentation and the free Microsoft English text to speech and speech recognition engines. The download is very large, 68 MB, so unless you have a high speed connection to the internet you might want to order the SDK CD from Microsoft.

…. Time passes while you download or wait for the postman ….

Ok, now you have the SAPI 5.1 SDK. Run the speechsdk51.exe to install it on your development system.

[ *** DELPHI 6 Users IMPORTANT ****
There is a bug in the type library import in Delphi 6 see article 2589. This sample will still work with the unit created by the type libary import in Delphi 6 but only because none of the events for the component are used. If you want to use any of the SPVoice events you will need to read article 2589 ]


What you need to do now is make Delphi aware of the new SAPI automation objects. To do this, start up Delphi 5 or 6 (I didn’t try earlier versions) and go to Project | Import Type Library. In the Import Type Library dialog highlight “Microsoft Speech Object Library (Version 5.1)”. If you don’t find this in the list then something’s wrong with the installation of SAPI 5.1.

Delphi is going to want to put the SAPI components on your ActiveX palette page. I recommend you put these on a new palette page called “SAPI 5” since the number of components installed is large (19). You may also want to choose a “Unit dir name” of something other than the default. Make sure the “Generate Component Wrapper” check box is checked and press the >Install< button.

In the Install dialog choose the “Into new package” tab and in the “File name:” field give a package name like “SAPI5.dpk” press the browse button and make sure the dpk is created in the same directory where you created the components. Actually this isn’t completely necessary it just helps keep things together. In the Install dialog’s Description field give some meaningful description like “SAPI 5 automation components”. Press OK

Press yes in the confirm dialog and the new components will be created and installed.

If you now look in the directory you specified for the components you should find SpeechLib_TLB.pas (and dcr) which contains all the component code as well as interface, const, type and other useful information. This is your most valuable piece of documentation on the SDK. I’ve found it even better than the Microsoft SAPI 5.1 documentation which is pretty good. This directory should also contain (if you followed the above instructions) the SAPI5.dpk which is your package source.

If you go to the far eastern end of your component palette you should find the new SAPI5 palette page with its 19 speech components.

Now for the fun part.

Let’s make an application that can synthesize speech. In Delphi start a new application and drop a button on the form. On the SAPI5 palette page find the SpVoice component and drop it on the form. On my machine this component is the 5th one reading from left to right.

Now create an onClick event for you button that looks something like this;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SpVoice1.Speak('Hello world!', SVSFDefault);
end;

Run the program and press the button. Cool hu?

At this level it’s amazingly simple. The SPVoice objects Speak method is very powerful. This power comes from the second parameter. For the above example I choose to use the default mode which causes the speak method to return only when the synthesis is complete, not to purge pending speech requests, to respond to special XML control tags embedded in the text.

The SDKs documentation is contained in sapi.chm which you will find in the  \Program Files\Microsoft Speech SDK 5.1\Docs\Help directory.

Sapi.chm contains a lot of information. To go directly to the meat of the subject go to the last folder on the outlines 1st level titled Automation and go down to SPVoice and then to the Speak method read what’s there and also be sure to follow the link to the SpeechVoiceSpeakFlags info. You will find that in addition to just speaking passed in text that can also do much more some of the more interesting flags are;
• Pass in a file name and speak the text in the file. (SVSFIsFilename)
• Make the function either return immediately (asynchronously) or only after the synthesis is complete(synchronously). If you speak asynchronously there are events available to fire when the speech is done. (SVSFlagsAsync)
• Embed flags in the text that can control various aspects of the synthesis like pitch, rate, emphasis, and much more (see the included White Paper titled “XML TTS Tutorial”). I found this feature a bit addicting as I attempted to make the synthesized voice sing.( SVSFIsXML)

One interesting thing I found (but not documented) was that you can speak a web sites title by setting the flag to SVSFIsFilenam and passing a URL. If you are connected to the internet, try replacing the speak line in the sample line with

  SpVoice1.Speak('http://www.o2a.com', SVSFIsFilename);

And run it.

Even more bizarre is you can use the speak method to play wav files. Try

  SpVoice1.Speak('C:\WINNT\MEDIA\Windows Logon Sound.wav', SVSFIsFilename);

There’s a lot more to SAPI then text to speech and there’s more to text to speech then what I’ve covered here. Hopefully this will be the first of a number of articles on SAPI but I’ll only do them if you’re interested so please be sure to comment. Also I’m completely open to suggestions on what you’d like to see next (if anything at all).

If you want to talk privately I’m at alecb@o2a.com.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Microsoft Speech Object Library (Version 5.1) missing in "Import type library" in Delphi5
    Odin Roll-Hansen (Sep 19 2007 12:13PM)

Hi
I followed the guidelines in this article (http://www.delphi3000.com/articles/article_2581.asp) but could not find Microsoft Speech Object Library (Version 5.1) in the "Import type library"-list in Delphi5. I only have the version 5.0 in the list
What to do?
Sincerely Odin
Respond

how can SPVoice speak french ?
    nidhal belmokhtar (Aug 24 2006 5:32PM)

I have downloaded an example in Delphi 7, which uses the SPVoice component. my application speaks english, but when a text is in french, the pronounciation has an english accent. I want it to speak french correctly without any accent. is it possible?
Respond

RE: how can SPVoice speak french ?
goo kachee (Sep 28 2006 9:57AM)

french is not surpport£¡Only english ,chinese and japanese (need to install the language packet)is surpported.
Respond

How to change the voice?
    Abdulaziz Jasser (Dec 6 2005 6:35AM)

Hi...I know SAPI comes with three voices. How to change the voice using TSpVoice component?
Respond

Can you give me an example about AudioOutput property of spvoice?
    thunder zhu (Jun 1 2002 6:31AM)

This article is very helpful.Now I can use spvoice to speak chinese.The  speech is played over my computers speakers. I want to save the speak
result to a wav file. I know I can change the AudioOutput property of spvoice. But I don't Know how to use it .Can you give me an example about AudioOutput property of spvoice? My Email:thunder_bird@163.net
Respond

RE: Can you give me an example about AudioOutput property of spvoice?
hj1688 mao (Mar 26 2003 9:24AM)

see sapi5.1 demo .
but i can't get event while text speech to wav file.
Respond

RE: RE: Can you give me an example about AudioOutput property of spvoice?
tauqeer (Jun 10 2003 5:30PM)

for voice wxample to get the voice
Respond

RE: Can you give me an example about AudioOutput property of spvoice?
anonymus (Mar 28 2003 4:18PM)

sorry that i put my question into a respond ;-) but when i read this thread, i thought that it is the best place for my question.

Im a rookie in speech synthesis and trying to figure out how to
change the properties of my wav-file-output. I will use the wavfiles
"realtime" in a ISDN-application that interacts like a telephone-
answerer. This application will respond according to the calling Number i.e. it looks up in the DataBase for the callingNumber and greets the caller  with some dedicated words for example->  ....."Hi Peter, im sorry that im not at home, but where are my CD's that i lend to you one year ago????????......... and so on  ;-)).

My application is able to respond in the way that it should be and everything works perfect with 8000 Hz wav-samples. What i need
is to know how to change the properties of my speechsynthesis
that my ISDN-App will receive the wav-files in the expected format.

thanx
Respond

RE: Can you give me an example about AudioOutput property of spvoice?
Tauqeer (Jun 10 2003 5:29PM)

for voice getting with coding
Respond

RE: Can you give me an example about AudioOutput property of spvoice?
Taqueer (Jun 10 2003 5:31PM)

Text to speech get the audiolevel in vc++
Respond

RE: Can you give me an example about AudioOutput property of spvoice?
gol mohammad fazli (Oct 21 2003 7:27AM)

give me an example about speech
Respond

Distributing
    Albert Tovmasyan (May 1 2002 6:36PM)

What files I must include to my application befor distributing it?
Respond

RE: Distributing
erturk varol (Sep 18 2004 8:58PM)

On The client computer must installed TTS Engine as I know.
Respond

Voices
    Victor Feria (Oct 27 2001 8:46AM)

The article is a big help. Maybe Alec can add some comments on how to access and assign available voices into a Tlist or ComboBox.
Respond

RE: Voices
Alec Bergamini (Oct 29 2001 1:10AM)

Hopefully I can do this in a future article. Problem is I can only do this stuff in free time and I don't have any right now. In august I had plenty.
Respond

Another question.
    boyface (Aug 24 2001 8:25AM)

yes, it's very nice.
after doing that, the application can speak chinese smoothly.
but, if english, it will speak letter by letter. Is there some
prolbem? or how can it speak english word by word?
Respond

RE: Another question.
Alec Bergamini (Aug 25 2001 5:08PM)

The sample application uses the default voice for your computer system. You must have Chinese selected as the default voice. You can go to the Speech icon in the control panel and select a different voice (like English) as the default.
Respond

the other question...
navy chen (Sep 6 2001 5:35AM)

   but when I use this in Delphi5+MSSpeech V5  ,it don't work!
   I drop the ' SpVoice '  into the form ,a error raise :"not support the interface' .why? must I use MsSpeech v5.1?
   btw,When does Dtalk support Speech v5?
   thanks !
   best regards!

Respond

RE: the other question...
Alec Bergamini (Sep 6 2001 3:59PM)

Yes, it is very important that you use 5.1. The 5.0 version does not have the automation objects. It has a type lib that you can import but the IDL has flaws and much of it doesn't work.
Respond

Delphi 6 Type Lib import bug
    Alec Bergamini (Aug 21 2001 8:13PM)

After writing this article I ran into a bug that effects only Delphi 6 users. The problem is documented in article #2589 and this article has been updated to reflect the problem.
Respond

More Information about this article
    Vimil Saju (Aug 21 2001 9:01AM)

It would be nice if you could give more info about this article.
Are there any components for converting speech to text
Respond

RE: More Information about this article
Alec Bergamini (Aug 21 2001 2:56PM)

Yes, "speech to text" is more commonly known as speech recognition and that is what the next article will be about. And yes this functionality is also covered by the SAPI SDK.
Respond

RE: RE: More Information about this article
Alec Bergamini (Aug 25 2001 6:40PM)

See Article ID # 2629. "Speech Part 2 - How to Add Simple Dictation speech recognition ..."
Respond

More on this article
    Vimil Saju (Aug 21 2001 8:56AM)

It would be nice if you can be give more information about this topic.  
Are there any components that converts speech to text?
Respond

Nice...
    Martin Glob (Aug 15 2001 10:35PM)

nice to see an article above the 'hello world' level :-)
Respond

RE: Nice...
Alec Bergamini (Aug 16 2001 12:44AM)

Sure make fun, but it does bring "hello world" to the level we sort of wanted when we originally did "hello world" years and years ago....

Scotty picks up the mouse and says "Computer...", but the computers just a Mac.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
A. B. Talal
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)