unit fTTS;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,  shellapi,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
  FMX.Edit, FMX.ListBox, FMX.Controls.Presentation, uTTS, bass_simple;

type
  TfrTTS = class(TFrame)
    Label1: TLabel;
    cbVoices: TComboBox;
    btnUpdateVoices: TButton;
    Label2: TLabel;
    edtText: TEdit;
    Label3: TLabel;
    btnSend: TButton;
    cbOutput: TComboBox;
    procedure btnUpdateVoicesClick(Sender: TObject);
    procedure btnSendClick(Sender: TObject);
    procedure cbVoicesChange(Sender: TObject);
    procedure cbOutputChange(Sender: TObject);
  private
    { Private declarations }
    tts: TTTS;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}
uses ugeneral;

procedure TfrTTS.btnSendClick(Sender: TObject);
var
  s, s1: string;

begin
  case cbOutput.ItemIndex of
    0:
      begin // this
        s := ExtractFilePath(ParamStr(0)) + 'piper\piper.exe';
        s1 := ExtractFilePath(ParamStr(0)) + 'piper\voices';
        if cbVoices.ItemIndex = -1 then
          exit;
        tts := TTTS.Create(s, s1);
        try
          tts.SetModel(cbVoices.Text);
          tts.TextToSpeech(edtText.Text, true);
        finally
          tts.Free;
        end;
      end;
    1:
      begin // SilentPlay
        ShellExecute(0, 'open', PChar(myConst.SilentPlay),
      PChar(Format('%s %s "%s"', ['2', cbVoices.Text, edtText.Text])), nil, 0);
      end;
   

  end;

end;

procedure TfrTTS.btnUpdateVoicesClick(Sender: TObject);
var
  s, s1: string;
  List: TStringList;
begin
  s := ExtractFilePath(ParamStr(0)) + 'piper\piper.exe';
  s1 := ExtractFilePath(ParamStr(0)) + 'piper\voices';

  tts := TTTS.Create(s, s1);
  List := TStringList.Create;
  try
    cbVoices.Items.Clear;
    List := tts.GetModelsList;
    cbVoices.Items.Assign(List);
  finally
    tts.Free;
    List.Free;
  end;
end;

procedure TfrTTS.cbOutputChange(Sender: TObject);
begin
db.WriteSetting('cbOutput',inttostr(cbOutput.ItemIndex));
end;

procedure TfrTTS.cbVoicesChange(Sender: TObject);
begin
db.WriteSetting('cbVoices',inttostr(cbVoices.ItemIndex));
end;

end.
