我是通过使用Delphi在2000 / NT / XP中创建OLE对象来实现的,如下所示:
Voice := CreateOLEObject('SAPI.SpVoice'); Voice.speak(...)
但是这在Vista中不起作用,我怎么能让我的程序只是在Vista中说一些文字?
解决方法
我刚刚尝试使用以下代码尝试(Vista Home Premium上的D2009),它可以正常工作!
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.
仅供参考,Brian Long有一个nice paper on using speech in Delphi programming …
(非常)晚更新:
为什么它可能无法在Vista中工作并在IDE之外提供EZeroDivide异常,请参阅此其他SO问题:Delphi SAPI Text-To-Speech