在 Win 10 中使用 TTS 和 Delphi



with Delphi XE8, Windows 8.1.语言-葡萄牙语-BR.

我使用代码(下面(来获取语音。它在 Win 8 中返回:

  • Microsoft 玛丽亚桌面 - 葡萄牙语(巴西(
  • Microsoft Zira Desktop -Ingles(美国(

我在 Win 10 中安装了该应用程序。在这里,我想使用男声("丹尼尔"(。我可以在 Windows 10 设置中看到,我已经安装了:

  • Microsoft 玛丽亚桌面 - 葡萄牙语(巴西(

  • Microsoft Zira Desktop -Ingles(美国(

  • Microsoft 玛丽亚-葡萄牙语(巴西(

  • Microsoft 丹尼尔-葡萄牙语(巴西(

    但是,我的德尔菲代码只继续返回:

  • Microsoft 玛丽亚桌面 -葡萄牙语(巴西(

  • Microsoft Zira Desktop -Ingles(美国(

其他声音没有列出,sapi声音吗? 可以使用它,作为样品,Microsoft丹尼尔葡萄牙语(巴西(,使 与德尔福的文字转语音?

voz := CreateOLEObject('SAPI.SpVoice');
if not VarIsEmpty(voz) then begin
vozes := voz.getVoices;
ComboVoz.Clear;
for i := 0 to vozes.Count - 1 do
ComboVoz.Items.Add(vozes.item(i).GetDescription);
end;

默认情况下,Microsoft移动语音被锁定,以便通过 SAPI 5 在文本转语音软件中使用。您可以通过简单的注册表调整来解锁它。下载存档,为您的语言和操作系统版本提取文件(32 位为"mobile_x86.reg",64 位为"mobile_x64.reg"(,在文件名上单击鼠标右键,然后选择上下文菜单项"合并"。 复制自

您正在寻找的是将与 delphi 本身一起导入的SpeechLib_tlb activex。

http://www.exceletel.com/support/whtpapers/speech/delphi.htm

代码示例

unit UnitF;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SpeechLib_TLB, OleServer, XPMan, ExtCtrls, ComCtrls, ENGINE,
TFlatCheckBoxUnit;
type
TPropriedsF = class(TForm)
SAPI: TSpVoice;
CBFA: TComboBox;
IMG: TImage;
XPManifest1: TXPManifest;
EDTEST: TEdit;
DEMVOZ: TButton;
TB: TTrackBar;
LAUT: TCheckBox;
APPLY: TButton;
BCANC: TButton;
BOK: TButton;
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure CBFAChange(Sender: TObject);
procedure DEMVOZClick(Sender: TObject);
procedure TBChange(Sender: TObject);
procedure APPLYClick(Sender: TObject);
procedure BCANCClick(Sender: TObject);
procedure BOKClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
PropriedsF: TPropriedsF;
VPT: string;
implementation
{$R *.dfm}
procedure TPropriedsF.FormShow(Sender: TObject);
var
SOTokenVoice: ISpeechObjectToken;  // See the MS SAPI SDK for info on
SOTokenVoices:ISpeechObjectTokens; // registry tokens that hold resources
i:       Integer;
begin
VPT:= 'Você selecionou X como voz padrão do sistema.';
//
SAPI.EventInterests := SVEAllEvents;
SOTokenVoices := SAPI.GetVoices('','');  // Use the registry tokens
for I := 0 to SOTokenVoices.Count - 1 do
begin
//For each voice, store the descriptor in the TStrings list
SOTokenVoice := SOTokenVoices.Item(i);
CBFA.Items.AddObject(SOTokenVoice.GetDescription(0), TObject(SOTokenVoice));
//Increment descriptor reference count to ensure it's not destroyed
SOTokenVoice._AddRef;
end;
if CBFA.Items.Count > 0 then
begin
CBFA.ItemIndex := CBFA.Items.IndexOf(SAPI.Voice.GetDescription(0));
end;
//
TB.Position := SAPI.Rate;
EDTEST.TEXT:= TROCA('X', SAPI.Voice.GetDescription(0), VPT);
end;
procedure TPropriedsF.CBFAChange(Sender: TObject);
var SOTokenVoice:  ISpeechObjectToken;
begin
SOTokenVoice   := ISpeechObjectToken(Pointer(CBFA.Items.Objects[CBFA.ItemIndex]));
SAPI.Voice := SOTokenVoice;
EDTEST.TEXT:= TROCA('X', SAPI.Voice.GetDescription(0), VPT);
end;
procedure TPropriedsF.DEMVOZClick(Sender: TObject);
begin
if SAPI.Voice = nil then
exit;
//
SAPI.Speak(EDTEST.Text, 1);
end;
procedure TPropriedsF.Button1Click(Sender: TObject);
var
SpFileStream1: TSpFileStream;
FileName : TFileName;
T: TSTRINGLIST;
I: INTEGER;
begin
T:= TSTRINGLIST.CREATE;
T.LoadFromFile(EXTRACTFILEPATH(PARAMSTR(0))+'LISTA.TXT');
FOR I:=0 TO T.COUNT-1 DO
BEGIN
FileName := extractfilepath(paramstr(0))+'RAQUEL'+T[I];
SpFileStream1 := TSpFilestream.Create(nil);
SpFileStream1.Open(FileName, SSFMCreateForWrite, False);
SAPI.AudioOutputStream := SPFileStream1.DefaultInterface;
SAPI.Speak(COPY(T[I], 1, POS('.', T[I])-1), SVSFDefault);
SPFileStream1.Close;
SpFileStream1.Free;
SLEEP(300);
END;
end;
procedure TPropriedsF.TBChange(Sender: TObject);
begin
SAPI.Rate:= TB.Position;
end;
procedure TPropriedsF.APPLYClick(Sender: TObject);
begin
APPLY.ENABLED:= FALSE;
//
//SAPI
//..
end;
procedure TPropriedsF.BCANCClick(Sender: TObject);
begin
CLOSE;
end;
procedure TPropriedsF.BOKClick(Sender: TObject);
begin
CLOSE;
end;
end.

相关内容

  • 没有找到相关文章

最新更新