[fpc-pascal] Microsoft SAPI on Freepascal

James Richters james.richters at productionautomation.net
Sun Jun 25 22:46:22 CEST 2023


I gave up on doing it directly, it seems SO convoluted to do with FPC with the COM unit and all this stuff I just don’t understand, 
and it’s SO simple to do with a VBS script in just 3 lines and it just works!  (it would only be 2 lines if I didn’t want Microsoft Zira)
 
So I decided to do this in the most ridiculous way possible.. but after 3 days of trying to get send something directly to SAPI with FPC ,
I’m done with it, and getting this to work was super easy. 
 
Computers are fast enough that I don’t need to waste my time tying to figure this out, just have FPC write out a VBS script, and run it with Process.Execute problem solved!
 
Here it is, maybe it will help someone else struggling to get something so simple to work:
 
{$mode objfpc}
Program Zira;
 
Uses
   SysUtils, Classes, Process;
 
Procedure Zira(ZiraZtring: AnsiString);
Var
   ScriptText: TStringList;
   Process: TProcess;
Begin
   ScriptText := TStringList.Create;
   ScriptText.Add('Set objVoice = CreateObject("SAPI.SpVoice")');
   ScriptText.Add('Set objVoice.Voice = objVoice.GetVoices().Item(1)');
   ScriptText.Add('objVoice.Speak "' + ZiraZtring + '"');
   ScriptText.SaveToFile('ZiraScript.vbs');
   Process := TProcess.Create(nil);
   Process.Executable := 'WScript.exe';
   Process.Parameters.Add('ZiraScript.vbs');
   Process.Execute;
   Process.WaitOnExit;
   ScriptText.Free;
   DeleteFile('ZiraScript.vbs');
End;
 
Begin
   Zira('Hello World');
End.


 
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Rafael Picanço via fpc-pascal
Sent: Sunday, June 25, 2023 2:17 PM
To: fpc-pascal at lists.freepascal.org
Cc: Rafael Picanço <cpicanco42 at gmail.com>
Subject: Re: [fpc-pascal] Microsoft SAPI on Freepascal
 
Hi James,
 
I am not familiar with variants and Ole objects, sorry about that. I found some people using code with Ole objects and it that seems to work, can you chack if it applies to your case?
 
https://stackoverflow.com/questions/17970573/using-word-ole-in-lazarus-freepascal
 
Best,
R
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230625/69ad7d9a/attachment-0001.htm>


More information about the fpc-pascal mailing list