Vista中的文本到语音
-
03-07-2019 - |
题
我是通过使用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.
仅供参考,有一篇关于在Delphi编程中使用语音的 Brian Long ......
(非常)晚更新:
为什么它可能无法在Vista中运行并在IDE之外提供EZeroDivide异常,请参阅另一个SO问题: Delphi SAPI Text-To-Speech
不隶属于 StackOverflow