Difference between revisions of "SAPI"

From Lazarus wiki
Jump to navigationJump to search
(Speech API/SAPI page with sample from forum. Handy for accessibility?)
 
m (Link to accessibility OSX VoiceOver)
Line 31: Line 31:
  
 
== OSX alternatives ==
 
== OSX alternatives ==
OSX has system wide text to speech functionality. <please expand this>
+
OSX has system wide text to speech functionality built in: VoiceOver. See [[LCL_Accessibility#Mac_OS_X_VoiceOver]]
  
 
[[Category:FPC]]
 
[[Category:FPC]]
 
[[Category:Lazarus]]
 
[[Category:Lazarus]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Revision as of 12:48, 15 August 2012

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