unit mainfrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, nrcommbox, nrclasses, nrcomm, nrcommtapi, nrwavebase,
  nrspeech;

type
  TForm1 = class(TForm)
    nrSpeech1: TnrSpeech;
    nrCommTAPI1: TnrCommTAPI;
    GroupBox1: TGroupBox;
    nrDeviceBox1: TnrDeviceBox;
    Button1: TButton;
    CheckBox1: TCheckBox;
    Button2: TButton;
    Edit1: TEdit;
    Button3: TButton;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    GroupBox3: TGroupBox;
    ListBox1: TListBox;
    Button4: TButton;
    Memo1: TMemo;
    Button5: TButton;
    ComboBox1: TComboBox;
    Label3: TLabel;
    cbVoices: TComboBox;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure nrCommTAPI1FatalError(Sender: TObject; ErrorCode,
      Detail: Cardinal; ErrorMsg: String; var RaiseException: Boolean);
    procedure nrSpeech1AfterPlay(Sender: TObject);
    procedure nrCommTAPI1LineConnected(Sender: TObject);
    procedure nrCommTAPI1LineDisconnected(Com: TObject; ByRemote: Boolean);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  nrCommTAPI1.DeviceConfigDialog;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  nrCommTAPI1.Voice:=True;
  nrCommTAPI1.WaitForIncomingCall;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  nrCommTAPI1.Voice:=True;
  nrCommTAPI1.Phone:=Edit1.Text;
  nrCommTAPI1.Call;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  nrCommTAPI1.HangUp;
end;

procedure TForm1.nrCommTAPI1FatalError(Sender: TObject; ErrorCode,
  Detail: Cardinal; ErrorMsg: String; var RaiseException: Boolean);
begin
  // Handling Fatal Errors ...
  ListBox1.Items.Add(ErrorMsg);
  // Don't show exception message box ...
  RaiseException:=False;
end;

procedure TForm1.nrSpeech1AfterPlay(Sender: TObject);
begin
  ListBox1.Items.Add('Speaking is finished');
end;

procedure TForm1.nrCommTAPI1LineConnected(Sender: TObject);
begin
  ListBox1.Items.Add('Connection established');
  ComboBox1.ItemIndex:=0;
  Button4Click(Sender);
end;

procedure TForm1.nrCommTAPI1LineDisconnected(Com: TObject;
  ByRemote: Boolean);
begin
  ListBox1.Items.Add('Line disconnected');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if ComboBox1.ItemIndex = 0
    then nrSpeech1.nrCommTAPI:=nrCommTAPI1
    else nrSpeech1.nrCommTAPI:=nil;
  nrSpeech1.Text.Text:=Memo1.Text;
  nrSpeech1.VoiceIndex := cbVoices.ItemIndex;
  nrSpeech1.Speak;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  nrSpeech1.Stop;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
  cbVoices.Items.Clear;
  for i:=0 to nrSpeech1.VoiceCount-1 do cbVoices.Items.Add(nrSpeech1.Voices[i]);
  cbVoices.ItemIndex:=nrSpeech1.VoiceIndex;
  ComboBox1.ItemIndex:=1;
end;

end.
