[fpc-pascal] Microsoft SAPI on Freepascal

James Richters james.richters at productionautomation.net
Tue Jun 27 01:04:13 CEST 2023


I appreciate the help with this.  I'm still confused.  
In my original post, I  already had CoInitialize,   CoUninitialize; and Unit
ComOBJ,  Unit Windows and Unit ActiveX I was still getting EOleError:
Variant does not reference an automation object.   

Do I need to do all this Change FPU stuff?

I'm sure I'm doing something wrong but I still can't get it to work. Here's
my original program.  I wasn't even trying to change the voice yet.  What do
I need to do to this to make it work?

James

{$mode objfpc}

uses
CRT, Windows, SysUtils, ComObj, Variants, OLEServer,  Classes,  ActiveX,
ShellApi;

var
  SavedCW: Word;
  SpVoice: Variant;
  MyWideString: WideString;
begin
  CoInitialize(nil);
  SpVoice := CreateOleObject('SAPI.SpVoice');
  MyWideString := WideString('Hello, the time is ' + TimeToStr(Now));
  Writeln(MyWideString);
  // Change FPU interrupt mask to avoid SIGFPE exceptions
  SavedCW := Get8087CW;
  try
    Set8087CW(SavedCW or $4);
    SpVoice.Speak(MyWideString, 0);
  finally
    // Restore FPU mask
    Set8087CW(SavedCW);
  end;
  Writeln('Press Any Key');
  ReadKey;
  CoUninitialize;
end.



More information about the fpc-pascal mailing list