[fpc-pascal] Microsoft SAPI on Freepascal
    Michael Van Canneyt 
    michael at freepascal.org
       
    Mon Jun 26 15:54:31 CEST 2023
    
    
  
On Sun, 25 Jun 2023, James Richters via fpc-pascal wrote:
> 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)
I don't know what people advised you, but what you want to do needs 3 lines
of code only:
I created a lazarus application, dropped a button and in the onclick I call
speak('hello'). It just works.
--
uses comobj;
procedure speak(s : string);
var
   v : olevariant;
begin
   v:=CreateOleObject('SAPI.SpVoice');
   v.Voice:=v.GetVoices().Item(1);
   v.Speak(s);
end;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
   speak('hello');
end;
--
No need to write a script, call tprocess etc. 
You can do everything right in fpc as simple as this.
Michael.
    
    
More information about the fpc-pascal
mailing list