⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settings.pas

📁 delphi下基于tapi的话音存储
💻 PAS
字号:
unit Settings;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,AMITAPILib_TLB ,AMIWAVELib_TLB , reg;

type
  TfrmSettings = class(TForm)
    GroupBox1: TGroupBox;
    ComboLineName: TComboBox;
    LabelTAPIVer: TLabel;
    CommandLine: TButton;
    CommandCaps: TButton;
    GroupBox2: TGroupBox;
    TextTelephoneNumber: TEdit;
    GroupBox3: TGroupBox;
    CheckAutoAnswer: TCheckBox;
    TextRingsBeforeAnswer: TEdit;
    Label1: TLabel;
    CheckTranslateNumbers: TCheckBox;
    CommandLocation: TButton;
    GroupBox4: TGroupBox;
    ComboSoundCardOut: TComboBox;
    Label2: TLabel;
    Label3: TLabel;
    GroupBox5: TGroupBox;
    GroupBox6: TGroupBox;
    OptionSoundCard: TRadioButton;
    OptionLine: TRadioButton;
    CommandWaveInCaps: TButton;
    CommandWaveOutCaps: TButton;
    ComboRecordFormat: TComboBox;
    ComboSoundCardIn: TComboBox;
    CommandOK: TButton;
    procedure ComboLineNameChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboSoundCardInChange(Sender: TObject);
    procedure ComboSoundCardOutChange(Sender: TObject);
    procedure ComboRecordFormatChange(Sender: TObject);
    procedure CommandOKClick(Sender: TObject);
    procedure CheckAutoAnswerClick(Sender: TObject);
    procedure CommandLineClick(Sender: TObject);
    procedure CommandCapsClick(Sender: TObject);
    procedure CommandLocationClick(Sender: TObject);
    procedure CommandWaveInCapsClick(Sender: TObject);
    procedure CommandWaveOutCapsClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

    function Iif(expr1:integer; expr2:integer; truepart:string; falsepart:string):string;  

var
  frmSettings: TfrmSettings;

implementation

uses Main;

{$R *.DFM}
var ItemData : array[0..7]of integer;

procedure TfrmSettings.ComboLineNameChange(Sender: TObject);
begin
  //Save in the registry the telephony line device name being used
  SaveSetting ('TapiProWavePro', 'Settings', 'Line Device', ComboLineName.Text);
  //Set the line name to use
  frmmain.amTapiPro1.LineName := ComboLineName.Text;
  CommandLocation.Enabled := True;
  //Display the negotiated TAPI version, lowest of application, OS and TSP
  LabelTAPIVer.Caption := 'TAPI V ' + inttostr((frmmain.amTapiPro1.TapiNegotiatedVersion and 4294901760) div 65536) + '.' + inttostr(frmmain.amTapiPro1.TapiNegotiatedVersion and 255);

end;

procedure TfrmSettings.ComboSoundCardInChange(Sender: TObject);
begin
 //Save in the registry the wave input device ID
 SaveSetting('TapiProWavePro', 'Settings', 'Sound Card Input', ComboSoundCardIn.ItemIndex);
end;

procedure TfrmSettings.FormCreate(Sender: TObject);
var i : integer;
    LineName : String;
    SavedLineName : String;
    SavedIndex : integer;
    ID : integer;
begin
 //Enumerate wave output devices
ComboSoundCardOut.Text := 'Select Sound Card';
 for i := 0 to  frmMain.amWavePro1.WaveOutNumDevs - 1 do
     ComboSoundCardOut.Items.add(frmMain.amWavePro1.WaveOutGetName(i));
 //Get saved wave out ID from registry
 ID := GetSetting('TapiProWavePro', 'Settings', 'Sound Card Output', -1);
 if not(ID = -1) then
  begin
   ComboSoundCardOut.ItemIndex := ID;
   ComboSoundCardOutChange(self);
  end;
 //Enumerate wave input devices
 ComboSoundCardIn.Text := 'Select Sound Card';
 for i := 0 to frmMain.amWavePro1.WaveInNumDevs - 1 do
     ComboSoundCardIn.Items.Add(frmMain.amWavePro1.WaveInGetName(i));
 //Get saved wave in ID from registry
  ID := GetSetting('TapiProWavePro', 'Settings', 'Sound Card Input', -1);
 if not(ID = -1) then
  begin
   ComboSoundCardIn.ItemIndex := ID;
   ComboSoundCardInChange(self);
  end; 

 //Fill combo with wave format data
 ComboRecordFormat.Text := 'Select Record Wave Format';
 ItemData[0] := am8000Hz8bit;
 ItemData[1] := am8000Hz16bit;
 ItemData[2] := am11025Hz8bit;
 ItemData[3] := am11025Hz16bit;
 ItemData[4] := am2205Hz8bit;
 ItemData[5] := am2205Hz16bit;
 ItemData[6] := am44100Hz8bit;
 ItemData[7] := am44100Hz16bit;

 //Get saved record format from registry
 ID := GetSetting('TapiProWavePro', 'Settings', 'Record Format', -1);
 if not(ID = -1) then //If valid saved format
     //set combo to saved format
     for i := 0 to ComboRecordFormat.Items.Count - 1 do
      begin
         if (ItemData[i] = ID) then
          begin
             ComboRecordFormat.ItemIndex := i;
          end;

 end;

 //Open the telephone line device
 if frmMain.amTapiPro1.LineOpen then frmMain.amTapiPro1.LineOpen := False;
 //If you want to translate the number using the Windows dialing properties the number
 //should be in canonical format eg. +1 (222) 222-2222 +CountryCode (AreaCode)-Number
 TextTelephoneNumber.Text := GetSetting('TapiProWavePro', 'Settings', 'Telephone Number', '');

 CheckAutoAnswer.Checked := GetSetting('TapiProWavePro', 'Settings', 'Auto Answer', True);
 if (CheckAutoAnswer.Checked = false) then
  TextRingsBeforeAnswer.Enabled := False
 else
  TextRingsBeforeAnswer.Enabled := True;
 TextRingsBeforeAnswer.Text := inttostr(GetSetting('TapiProWavePro', 'Settings', 'Rings Before Answer', 2));

 CheckTranslateNumbers.Checked := GetSetting('TapiProWavePro', 'Settings', 'Translate Numbers', True);
 
 //The first time this app is run, the telephony line device to be used, will not have been
 //saved in the registry, so display the following message to the user
 ComboLineName.Text := 'Select telephony line device';
 //retrieve from the registry the name of the telephony line device to be used
 SavedLineName := GetSetting('TapiProWavePro', 'Settings', 'Line Device', 'Not Set');
 
 SavedIndex := -1;
 
 //Enumerate TAPI Line devices, devices are numbered starting at 0
 for i := 0 to frmMain.amTapiPro1.NumberOfLines - 1 do
  //Get the line name numbered i, this will also set the TapiNegotiatedVersion and
  //the DevCaps properties to valid values for the line device numbered i
  begin
   LineName := frmMain.amTapiPro1.GetLineName(i);
   if (frmMain.amTapiPro1.TapiNegotiatedVersion > 0) then
    //If amTapi was able to negotiate a TAPI version then add the line device name to the combo
    begin
     ComboLineName.Items.add(LineName);
     //If this is the line name saved in the registry save the line number
     if (LineName = SavedLineName) then SavedIndex := ComboLineName.Items.Count - 1;
    end;
  end;
  //If we found the line name the SavedIndex allows us to set the combo to the saved line name.
  if not(SavedIndex = -1) then
   begin
    ComboLineName.ItemIndex := SavedIndex;
    ComboLineNameChange(self);
   end;

end;

procedure TfrmSettings.ComboSoundCardOutChange(Sender: TObject);
begin
 //Save in the registry the wave input device ID
 SaveSetting('TapiProWavePro', 'Settings', 'Sound Card Output', ComboSoundCardOut.ItemIndex);

end;

procedure TfrmSettings.ComboRecordFormatChange(Sender: TObject);
begin
 //Save in the registry the wave record format
 SaveSetting('TapiProWavePro', 'Settings', 'Record Format', ItemData[ComboRecordFormat.ItemIndex]);

end;

procedure TfrmSettings.CommandOKClick(Sender: TObject);
begin
  //Save some settings in the registry
  SaveSetting('TapiProWavePro', 'Settings', 'Telephone Number', TextTelephoneNumber.Text);
  SaveSetting('TapiProWavePro', 'Settings', 'Auto Answer', CheckAutoAnswer.Checked);
  SaveSetting('TapiProWavePro', 'Settings', 'Translate Numbers', CheckTranslateNumbers.Checked);
  SaveSetting('TapiProWavePro', 'Settings', 'Rings Before Answer', strtoint(TextRingsBeforeAnswer.Text));

  if GetSetting('TapiProWavePro', 'Settings', 'Line Device', 'Not Set') = 'Not Set' then
   begin
    ShowMessage('You have not selected a telephony device');
    Exit;
   end;

  if (GetSetting('TapiProWavePro', 'Settings', 'Sound Card Output', -1)=-1) then
   begin
    ShowMessage('You have not selected a sound card output device');
    Exit;
   end;

  if (GetSetting('TapiProWavePro', 'Settings', 'Sound Card Input', -1)=-1) then
   begin
    ShowMessage('You have not selected a sound card intput device');
    Exit;
   end;

  if (GetSetting('TapiProWavePro', 'Settings', 'Record Format', -1)=-1) then
   begin
    ShowMessage('You have not selected a recording wave format');
    Exit;
   end;
  self.close;

end;

procedure TfrmSettings.CheckAutoAnswerClick(Sender: TObject);
begin
 if not CheckAutoAnswer.Checked then TextRingsBeforeAnswer.Enabled:=false
  else TextRingsBeforeAnswer.Enabled:=true;
end;

procedure TfrmSettings.CommandLineClick(Sender: TObject);
begin
 frmMain.amTapiPro1.ShowLineDialog (self.handle);
end;

procedure TfrmSettings.CommandCapsClick(Sender: TObject);
var strCaps : string;
    cps:integer;
begin
// Display the capabilities of the telephony line device seclected by the LineName property
 cps:= frmmain.amTapiPro1.DevCaps;
 strCaps := 'Media Mode Capabilities:' + #9 + '          Supported' + #13#10 + #13#10;
 strCaps := strCaps + #9 + 'Automated Voice ' + #9 + IIf(cps, AUTOMATEDVOICE, 'Yes', 'No') + #13#10;
 strCaps := strCaps + #9 + 'Interactive Voice ' + #9 +IIf(cps, INTERACTIVEVOICE, 'Yes', 'No') + #13#10;
 strCaps := strCaps + #9 + 'Data Modem ' + #9 + #9 + IIf(cps, DATAMODEM, 'Yes', 'No') + #13#10;
 strCaps := strCaps + #9 + 'G3 Fax ' + #9 + #9 + #9 + IIf(cps, G3FAX, 'Yes', 'No') + #13#10;
 strCaps := strCaps + #9 + 'G4 Fax ' + #9 + #9 + #9 +   IIf(cps, G4FAX, 'Yes', 'No') + #13#10;
 strCaps := strCaps + #13#10 + 'General Capabilities:' + #9 +  '          Supported' + #13#10;
 strCaps := strCaps  + #9 + 'Caller ID ' + #9 + #9 + IIf(cps, CID, 'Yes', 'No') + #13#10;
 strCaps := strCaps  + #9 + 'Monitor DTMF Digits ' + #9 + IIf(cps, MONDIGITS, 'Yes', 'No') + #13#10;
 strCaps := strCaps  + #9 + 'Generate DTMF Digits ' + #9 + IIf(cps, GENDIGITS, 'Yes', 'No') + #13#10;

 Showmessage(frmmain.amTapiPro1.LineName + ' Capabilities' + #13#10 + strCaps);

end;

function Iif(expr1:integer; expr2:integer; truepart:string; falsepart:string):string;
begin
if ((expr1 and expr2)>0) then result:=truepart else result:=falsepart;
end;


procedure TfrmSettings.CommandLocationClick(Sender: TObject);
var NumberToDisplay : WideString;
begin
    NumberToDisplay := TextTelephoneNumber.Text;
    //NumberToDisplay is in canonical format, can be a null string but if we pass in a telephone
    //number the user will see the effects of any changes made to the dialing rules in the Location Dialog
    if NumberToDisplay='' then
         if not (MessageDlg('If you set a default telephone number you will see the effect of' + #13#10 +
                            'changing the dialing rules at the bottom of the Location dialog.' + #13#10 +
                            'Do you wish to set the default telephone number?', mtWarning, [mbYes, mbNo],0)=mrYes) then
           begin
            NumberToDisplay:=' ';
            frmMain.amTapiPro1.ShowLocationDialog (self.handle, NumberToDisplay);
           end;
end;

procedure TfrmSettings.CommandWaveInCapsClick(Sender: TObject);
var strCaps : String;
    Caps : integer;
    WaveInID : integer;
    Title : string;
begin
 if OptionSoundCard.Checked then
  begin
     WaveInID := ComboSoundCardIn.itemIndex;
     Title:='Sound card';
  end
 else
  begin
     frmMain.amTapiPro1.LineOpen := True;
     WaveInID := frmMain.amTapiPro1.LineWaveInID;
     Title := frmMain.amTapiPro1.LineName;
  end;
 if (WaveInID = -1) then
  begin
     ShowMessage ('No wave input device');
     Exit;
  end;

 Caps := frmMain.amWavePro1.WaveInGetCaps(WaveInID);

 strCaps := Title + #13#10 + 'Natively supported record formats:' + #13#10;

 strCaps := strCaps + '8kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am8000Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '8kHz, 16 Bit ' + #9 + #9 + IIf(Caps , am8000Hz16bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '11.25kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am11025Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '11.25kHz, 16 Bit ' + #9 + IIf(Caps , am11025Hz16bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '22.05kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am2205Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '22.05kHz, 16 Bit ' + #9 + IIf(Caps , am2205Hz16bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '44.1kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am44100Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '44.1kHz, 16 Bit ' + #9 + #9 + IIf(Caps , am44100Hz16bit, 'Yes', 'No') + #13#10;

 ShowMessage(strCaps);
 frmMain.amTapiPro1.LineOpen := False;
end;

procedure TfrmSettings.CommandWaveOutCapsClick(Sender: TObject);
var strCaps : String;
    Caps : integer;
    WaveOutID : integer;
    Title : string;
begin
 if OptionSoundCard.Checked then
  begin
   WaveOutID := ComboSoundCardOut.ItemIndex;
   Title:='Sound card';
  end 
 else
  begin
   frmMain.amTapiPro1.LineOpen := True;
   WaveOutID := frmMain.amTapiPro1.LineWaveOutID;
   Title := frmMain.amTapiPro1.LineName;
  end;
 if WaveOutID = -1 then
  begin
   Showmessage('o wave output device');
   Exit;
  end;

 Caps := frmMain.amWavePro1.WaveOutGetCaps(WaveOutID);
 strCaps := Title + #13#10 + 'Natively supported record formats:' + #13#10;
 strCaps := strCaps + '8kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am8000Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '8kHz, 16 Bit ' + #9 + #9 + IIf(Caps , am8000Hz16bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '11.25kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am11025Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '11.25kHz, 16 Bit ' + #9 + IIf(Caps , am11025Hz16bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '22.05kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am2205Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '22.05kHz, 16 Bit ' + #9 + IIf(Caps , am2205Hz16bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '44.1kHz, 8 Bit ' + #9 + #9 + IIf(Caps , am44100Hz8bit, 'Yes', 'No') + #13#10;
 strCaps := strCaps + '44.1kHz, 16 Bit ' + #9 + #9 + IIf(Caps , am44100Hz16bit, 'Yes', 'No') + #13#10;
 ShowMessage(strCaps);
 frmMain.amTapiPro1.LineOpen := False;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -