在Win 10中与Delphi一起使用TTS

时间:2018-06-20 12:06:41

标签: delphi text-to-speech

使用Delphi XE8,Windows 8.1。语言-葡萄牙语-BR。

我使用下面的代码来表达声音。它在Win 8中返回:

  • Microsoft Maria Desktop-葡萄牙语(巴西)
  • Microsoft Zira Desktop -Ingles(美国)

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

  • Microsoft Maria Desktop-葡萄牙语(巴西)
  • Microsoft Zira Desktop -Ingles(美国)
  • Microsoft Maria-Portuguese(巴西)
  • Microsoft Daniel-Portuguese(巴西)

    但是,我的delphi代码仅继续返回:

  • Microsoft Maria Desktop-葡萄牙语(巴西)
  • Microsoft Zira Desktop -Ingles(美国)

是否没有列出其他声音,sapi声音? 可以使用它作为示例,例如Microsoft Daniel-Portuguese(巴西) 用Delphi进行文字转语音?

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;

2 个答案:

答案 0 :(得分:0)

默认情况下,Microsoft移动语音已被锁定,可以通过SAPI 5在文本语音转换软件中使用。您可以通过简单的注册表调整将其解锁。下载archive,解压缩您所用语言和操作系统版本的文件(对于32位是“ mobile_x86.reg”,对于64位是“ mobile_x64.reg”),在文件名,然后选择上下文菜单项“合并”。 从

复制

答案 1 :(得分:-3)

您正在寻找的是您将与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.
相关问题