What is it
SAPI stands for Speech Application Programming Interface, a Microsoft Windows API used to perform text-to-speech (TTS).
Use with Free Pascal
Lazarus / Free Pascal can use this interface to perform TTS. Source: forum post: 
On Windows Vista and above, you will run in trouble with the FPU interrupt mask (see ). The code dealing with SavedCW is meant to work around this.
uses ...,comobj; var SavedCW: Word; SpVoice: Variant; begin SpVoice := CreateOleObject('SAPI.SpVoice'); // Change FPU interrupt mask to avoid SIGFPE exceptions SavedCW := Get8087CW; try Set8087CW(SavedCW or $4); SpVoice.Speak('hi', 0); finally // Restore FPU mask Set8087CW(SavedCW); end;
For the options available with SpVoice.Speak and other SpVoice methods see http://msdn.microsoft.com/en-us/library/ms723609(v=vs.85).aspx.
Changing the FPU interrupt mask can be done at any moment before loading the ole object and if your application is not using any floating point arithmetic there is no need to reset the FPU interrupt mask to its original value.
Assigning text to a variable. A WideString must used.
File:procedure TForm1.Button1Click(Sender: TObject); Var SpVoice1: Variant; VoiceString: WideString; // WideString must be used to assign variable for speech to function, can be Global. begin SpVoice1 := CreateOleObject('SAPI.SpVoice'); // Can be assigned in form.create VoiceString := Button1.Caption; // variable assignment SpVoice1.Speak(VoiceString,0); end;
Thank you nsunny from 2013 post.
Windows, Linux, OSX alternatives
An alternative on Windows is to use espeak. eSpeak has 11 voices, (7 male and 4 female) and is cross platform supporting Windows, Mac and Linux. It also has many command line parameters which can be used to further improve the speech. When coding, an eSpeak installation can be used and a stand-alone option is available as well.
For a code example, please see the espeak article.
Apart from espeak, on Linux/Unix, there are some other command line Text To Speech engines, that may also offer access via APIs. An example is the festival engine.
OSX has a system wide text to speech functionality built in: see Mac OS X Text-to-Speech for using text to speech directly (no screenreading)
There's also a screenreader, VoiceOver. See LCL_Accessibility#Mac OS X VoiceOver
- espeak - Cross platform free Text to Speech engine