Text to speech in Vista

限于喜欢 提交于 2019-12-06 02:31:38

问题


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?


回答1:


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...


(Very) Late Update:

For why it might not work in Vista and give an EZeroDivide exception outside the IDE, see this other SO question: Delphi SAPI Text-To-Speech



来源:https://stackoverflow.com/questions/207653/text-to-speech-in-vista

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!