这个其实很久很久以前就实现过了,但就是因为太久了,基本上忘完了.昨天重新研究了一下,为了以后不再再重新研究,所以做个简单记录.
- 导入封装TTS引擎
- 程序中调用
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages,
System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
SpeechLib_TLB, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1:
TButton;
Memo1:
TMemo;
Button2:
TButton;
Button3:
TButton;
procedure
FormCreate(Sender: TObject);
procedure
Button1Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
procedure
Button3Click(Sender: TObject);
private
fVoce:
ISpeechVoice;
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.
-
当然微软的tts很强大,还可以识别语音,因此可以用来编写语音控制程序.具体可以看微软的MSDN资料很全的.对于我来说以后能找到地方就行了
|