unit uttsTradutor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, uttsPortug, uttsPreproc, uttsSintese, mmsystem;

type
  TForm1 = class(TForm)
    e_texto: TEdit;
    b_compilar: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    b_falar: TButton;
    b_parar: TButton;
    b_inicTrad: TButton;
    e_tradutor: TEdit;
    e_excessao: TEdit;
    b_preproc: TButton;
    l_preproc: TLabel;
    e_base: TEdit;
    c_emArquivo: TCheckBox;
    c_suavizar: TCheckBox;
    e_destino: TEdit;
    Label2: TLabel;
    procedure b_pararClick(Sender: TObject);
    procedure b_falarClick(Sender: TObject);
    procedure b_inicTradClick(Sender: TObject);
    procedure b_compilarClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure b_preprocClick(Sender: TObject);
    procedure e_textoKeyPress(Sender: TObject; var Key: Char);
  private
    procedure carregaBase;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.b_pararClick(Sender: TObject);
begin
    sndPlaySound (NIL, snd_async);
end;

procedure TForm1.carregaBase;
begin
    carregaBaseDifones (e_base.Text);
end;

procedure TForm1.b_falarClick(Sender: TObject);
begin
    suavizaJuncao := c_suavizar.Checked;
    if c_emArquivo.Checked then
        falaDifones (memo1.lines, e_destino.Text)
    else
        falaDifones (memo1.lines, '');
end;

procedure TForm1.b_inicTradClick(Sender: TObject);
begin
    fimTradutor;
    if not inicTradutor (e_tradutor.Text, e_excessao.Text) then
        showMessage ('Erro na base de dados do compilador');
    carregaBase;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
    fileMode := fmOpenRead;
    b_inicTradClick (sender);
end;

procedure TForm1.b_compilarClick(Sender: TObject);
var fonemas: string;
begin
     compilaFonemas (e_texto.Text, fonemas);
     if length (fonemas) > 0 then
         memo1.SetTextBuf(@fonemas[1]);
end;

procedure TForm1.b_preprocClick(Sender: TObject);
begin
    l_preproc.Caption := preProcessa (e_texto.text);
end;

procedure TForm1.e_textoKeyPress(Sender: TObject; var Key: Char);
begin
    if key = #$0d then
        begin
            b_compilarClick(Sender);
            b_falarClick(Sender);
        end;
end;

end.

