在Vista中进行文字转语音 [英] Text to speech in Vista
问题描述
我是通过在2000 / NT / XP中用Delphi创建OLE对象来做到这一点的,如下所示:
I did it by creating OLE object with Delphi in 2000/NT/XP as following:
Voice := CreateOLEObject('SAPI.SpVoice');
Voice.speak(...)
但这在Vista中不起作用,如何我可以让我的程序在Vista中简单地说些文本吗?
But this does not work in Vista, how can I make my program simply speak some text in Vista?
推荐答案
我刚刚尝试了以下操作(在Vista Home Premium上为D2009),
I just tried (D2009 on Vista Home Premium) with the following code and it works!
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 ...
FYI, there is a nice paper on using speech in Delphi programming by Brian Long...
(非常)较晚更新:
为什么它可能无法在Vista中工作并给出IDE之外的EZeroDivide异常,请参阅以下另一个SO问题: Delphi SAPI文本到语音
For why it might not work in Vista and give an EZeroDivide exception outside the IDE, see this other SO question: Delphi SAPI Text-To-Speech
这篇关于在Vista中进行文字转语音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!