Luiz Alves
Luiz Alves

Reputation: 2645

Using TTS with Delphi in Win 10

with Delphi XE8, Windows 8.1. Language-Portuguese-BR.

I use the code(below) to get voices. It returns in Win 8:

I installed the app in Win 10. Here, I want to use a male voice('Daniel'). I can see in Windows 10 settings, I have installed:

Is the other voices not listed, sapi voices? Is possible to use it, for sample, Microsoft Daniel-Portuguese(Brazil), to make text to speech with 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;

Upvotes: 1

Views: 3269

Answers (2)

benmakp benmakn
benmakp benmakn

Reputation: 61

By default, the Microsoft mobile voice is locked for using in text-to-speech software via SAPI 5. You can unlock it with a simple registry tweak. Download the archive, extract the file for your language and for your version of the operating system ("mobile_x86.reg" for 32-bit and "mobile_x64.reg" for 64-bit), click the right mouse button on the file's name and choose the context menu item "Merge". copied from

Upvotes: 0

Carl
Carl

Reputation: 131

What you are looking for is the SpeechLib_tlb activex that you will import with the delphi itself.

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

Code Sample

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.

Upvotes: -3

Related Questions