Mega Code Archive

 
Categories / Delphi / Examples
 

Delphi talks - using speech technology with your delphi apps

There is not very much needed to enable Text to Speech to work in your applications. In this example I'm going to show how we can gain access to Speech Libraries compatible with Microsoft's Speech API (SAPI) using Delphi's ActiveX/COM features, in particular Automation Objects. There's just a few lines of code needed. If you want the project files, press here: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComObj; type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private VTxt: variant; procedure Speak(Text: string); public { Public declarations } end; var Form1: TForm1; const vtxtst_SPREADSHEET = $40; vtxtsp_VERYHIGH = $80; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin VTxt:= CreateOLEObject('Speech.VoiceText'); try VTxt.Register('', Application.ExeName); except on EOLEException do end; end; procedure TForm1.Speak(Text: string); var n: integer; begin for n:= 1 to Length(Text) do if not (Text[n] in ['a'..'z', 'A'..'Z', '0'..'9', ' ']) then Exit; VTxt.Speak(Text, vtxtst_SPREADSHEET or vtxtsp_VERYHIGH); end; procedure TForm1.Button1Click(Sender: TObject); begin Speak('Using Speech Technology with your Delphi Applications'); end; end.