Programmatically talk using Microsoft Sam

posted 11 Mar 2010, 16:46 by Delphi Basics   [ updated 27 Mar 2010, 14:24 ]
Text to speech: programmatically talk using Microsoft Sam.  Speech synthesis works on any operating system which has SAPI DSK installed since it uses Microsoft Speech API.

In a formed application:

uses
  COMobj

procedure TForm1.Button1Click(Sender: TObject);
var
  voice: OLEVariant;
begin
    voice := CreateOLEObject('SAPI.SpVoice');
    voice.Speak('This is Microsoft Sam saying Delphi Basics', 0);
end;

In a formless application:
program Project1;

uses
  COMobj,
  ActiveX;

var
  voice: OLEVariant;

begin
    if paramstr(1) = '' then exit;
    try
      CoInitialize(nil);
      voice := CreateOLEObject('SAPI.SpVoice');
      voice.Speak(paramstr(1), 0);
    Finally
      CoUnInitialize;
    end;
end.

To display the voice that is speaking [Microsoft Sam]
ShowMessage(voice.voice.getdescription(0));

To read more on Speech Synthesis & Speech Recognition Using SAPI 5.1,visit: http://edn.embarcadero.com/article/29583.

Delphi source code of projects hosted by the article above are mirrored below.
Instructions are including for compiling on Delphi 2007.



Only Delphi source code is included in the archive.

ċ
TextToSpeech.7z
(43k)
Delphi Basics,
11 Mar 2010, 17:33
Comments