SAPI

From Free Pascal wiki
Revision as of 12:48, 15 August 2012 by BigChimp (talk | contribs) (Link to accessibility OSX VoiceOver)
Jump to navigationJump to search

What is it

SAPI stands for Speech Application Programming Interface, a Microsoft Windows API used to perform text-to-speech (TTS).

Use with FreePascal

Lazarus/FreePascal can use this interface to perform TTS. Source: forum post: [1]

On Windows Vista and above, you will run in trouble with the FPU interrupt mask (see [2]). The code dealing with SavedCW is meant to work around this.

uses
//... to do: what to add here?? Ludo's OLE/ActiveX library probably...
var
  SavedCW: Word;
  SpVoice: Variant;
begin
  SpVoice := CreateOleObject('SAPI.SpVoice');
  // Change FPU mask to avoid SIGSEGV  
  SavedCW := Get8087CW;
  try
    Set8087CW(SavedCW or $4);
    SpVoice.Speak('hi', 0);
  finally
    // Restore FPU mask
    Set8087CW(SavedCW);
  end;
  //todo: clean up object

Linux/Unix alternatives

On Linux/Unix, there are some command line Text To Speech engines, that may also offer access via APIs. An example is the festival engine.

OSX alternatives

OSX has system wide text to speech functionality built in: VoiceOver. See LCL_Accessibility#Mac_OS_X_VoiceOver