[fpc-pascal] Microsoft SAPI on Freepascal
James Richters
james.richters at productionautomation.net
Sun Jun 25 15:28:13 CEST 2023
Ooops forgot the link:
https://wiki.lazarus.freepascal.org/SAPI
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of
James Richters via fpc-pascal
Sent: Sunday, June 25, 2023 8:52 AM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Cc: James Richters <james.richters at productionautomation.net>
Subject: [fpc-pascal] Microsoft SAPI on Freepascal
I am trying to get Microsoft speech synthesis to work with Freepascal. I am
trying to follow the guide here:
I don't know what I am doing wrong. SAPI is working on my system, because
the TTSApp Demo that comes with the
Microsoft Speech SDK works fine.
Here is my test program:
{$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');
// Change FPU interrupt mask to avoid SIGFPE exceptions
MyWideString := WideString('Hello, the time is ' + TimeToStr(Now));
Writeln(MyWideString);
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.
Whenever my program gets to:
SpVoice.Speak(MyWideString, 0);
Even if I hardcode something like:
SpVoice.Speak('Hello', 0);
I always get:
Running "i:\programming\TTS.exe "
Hello, the time is 8:41:27
An unhandled exception occurred at $0041FC90:
EOleError: Variant does not reference an automation object
$0041FC90
$00424DAD
$0040BB31
$00401A8A main, line 21 of i:\programming\TTS.pas
I don't really understand what this means, and I can't find a complete
sample program that I can just compile and run. I feel I must be missing
something but I don't know what it is.
Any help is greatly appreciated!
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230625/f8d0dfce/attachment-0001.htm>
More information about the fpc-pascal
mailing list