|
发表于 2019-5-29 23:10:09
|
显示全部楼层
RE: Lazarus for 文本转语音程序(Lazaurs中文社区首发)
本帖最后由 bruce0829 于 2019-5-29 23:11 编辑
先試出講英文的
uses ...., comobj;
//參考 http://wiki.freepascal.org/SAPI
procedure TForm1.Button1Click(Sender: TObject);
var SavedCW: Word;
SpVoice: Variant;
begin
SpVoice := CreateOleObject('SAPI.SpVoice'); //use comobj
// Change FPU interrupt mask to avoid SIGFPE exceptions
SavedCW := Get8087CW;
try
Set8087CW(SavedCW or $4);
SpVoice.Speak('This is a book, that is a pen', 0); //播放 'This is a book, that is a pen'
finally
// Restore FPU mask
Set8087CW(SavedCW);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var SpVoice1: Variant;
VoiceString: WideString; // WideString must be used to assign variable for speech to function, can be Global.
begin
SpVoice1 := CreateOleObject('SAPI.SpVoice'); // Can be assigned in form.create
VoiceString := Button2.Caption; // variable assignment //播放 Button2.Caption (:='Lazarus is the best')
SpVoice1.Speak(VoiceString,0);
end; |
|