views:

1423

answers:

3

I did it by creating OLE object with Delphi in 2000/NT/XP as following:

Voice := CreateOLEObject('SAPI.SpVoice');
Voice.speak(...)

But this does not work in Vista, how can I make my program simply speak some text in Vista?

+3  A: 

I just tried (D2009 on Vista Home Premium) with the following code and it works!

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Voice: Variant;
begin
  Voice := CreateOLEObject('SAPI.SpVoice');
  Voice.speak('Hello World');
end;

end.

FYI, there is a nice paper on using speech in Delphi programming by Brian Long...

François
Thanks for the paper. But, running the code you showed, in Vista, I get the error "Floating point division by zero". Did you test it in Vista? (I built it with BDS2006 in Windows XP and ran the executable in Vista)
I did build and test in Vista (on the same machine)
François
thanks François. It works with the component in a the paper you suggested (http://www.blong.com/Conferences/DCon2002/Speech/SAPI51/SAPI51.htm)
A: 

Thanks for the paper. But, running the code you showed, in Vista, I get the error "Floating point division by zero". Did you test it in Vista? (I built it with BDS2006 in Windows XP and ran the executable in Vista)

François said that he compiled in Vista. Have you tried that?
Argalatyr
I haven't got Delphi in Vista. But it works with the component in the paper tha François suggested (http://www.blong.com/Conferences/DCon2002/Speech/SAPI51/SAPI51.htm)
A: 

Works when run from IDE (Turbo 2006) but gives floating point error as above when run outside IDE?

I built it with BDS2006 in Windows XP and ran the executable in Vista. It doesn't work in Vista outside IDE (inside IDE I didn't test).