delphi下调用微软的TTS语音
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SpeechLib_TLB,StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
fVoce: ISpeechVoice;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if fVoce.Status.RunningState = SRSEDone then fVoce.Speak(Memo1.Text, SVSFlagsAsync);
{1.状态判断很有必要,否者,连续点击的话,会一遍遍的重复.
2.采用异步模式(SVSFlagsAsync)才不互影响主程序的运行}
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
fVoce.Pause;
fVoce.Status;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
fVoce.Resume;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
fVoce := CoSpVoice.Create;
end;
end.