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

📄 main.pas

📁 delphi下基于tapi的话音存储
💻 PAS
📖 第 1 页 / 共 2 页
字号:
 CommandPlay.Enabled := False;
 CommandRecord.Enabled := False;
end;

procedure TfrmMain.CommandStopClick(Sender: TObject);
begin
 amWavePro1.StopPlay;
 amWavePro1.StopRecord;
end;

procedure TfrmMain.CommandRecordClick(Sender: TObject);
var RecordFormat : integer;
    SoundCardID : integer;
begin
 //Get saved wave record format from registry
 RecordFormat := GetSetting('TapiProWavePro', 'Settings', 'Record Format', -1);
 If (RecordFormat = -1) Then
  begin
     ShowMessage('No record format selected in the settings menu');
     Exit;
  end;
 //Set the record format 
 amWavePro1.RecordFormat := RecordFormat;
 if OptionRecordFile.Checked then
   amWavePro1.RecordFilename := 'Record.wav'
 else
   amWavePro1.RecordFilename := ''; //For silence detection only

 if OptionSoundCard.Checked Then
  begin
  //Get saved wave input ID from registry
  SoundCardID := GetSetting('TapiProWavePro', 'Settings', 'Sound Card Input', -1);
  if (SoundCardID = -1) then
   begin
    ShowMessage ('No sound card selected in the settings menu');
    Exit;
   end;
  amWavePro1.Record_(SoundCardID);
  end
 else
  //Get the telephone line wave input device ID from amTapi amWavePro1.Record_(WaveInputID);
  amWavePro1.Record_(amTapiPro1.LineWaveInID);
  
 CommandStop.Enabled := True;
 CommandRecord.Enabled := False;
 CommandPlay.Enabled := False;
end;

procedure TfrmMain.SliderPlayVolumeChange(Sender: TObject);
begin
amWavePro1.PlayVolume := SliderPlayVolume.Position - 100;
end;

procedure TfrmMain.SliderRecordVolumeChange(Sender: TObject);
begin
  amWavePro1.RecordLevel := SliderRecordVolume.Position - 100;
end;

procedure TfrmMain.amTapiPro1CallerID(Sender: TObject; const Number,
  Name: WideString; Flags: Integer);
begin
 //This event will fire when ever Caller ID info is availble for an incoming call
 //the event may fire more than once for a call, each time giving further information as it becomes available
 if (Flags And LINECALLPARTYID_NAME) > 0 then TextCallState.SelText := 'Name: ' + Name + #13#10;
 if (Flags And LINECALLPARTYID_NUMBER) > 0 then TextCallState.SelText := 'Number: ' + Number + #13#10;
 if (Flags And LINECALLPARTYID_BLOCKED) > 0 then TextCallState.SelText := 'Caller ID blocked' + #13#10;
 if (Flags And LINECALLPARTYID_OUTOFAREA) > 0 then TextCallState.SelText := 'Caller out of area' + #13#10;
 if (Flags And LINECALLPARTYID_UNKNOWN) > 0 then TextCallState.SelText := 'Caller ID unknown' + #13#10;

 //additional constants not used in this application
 //LINECALLPARTYID_PARTIAL The CID is partial more may be known later
 //LINECALLPARTYID_UNAVAILABLE No CID yet but may become available later
 end;

procedure TfrmMain.amTapiPro1CallState(Sender: TObject;
  const State: WideString);

begin
 //Display all messages
 TextCallState.Lines.Add(State);
 //Don't let this grow too big
 if TextCallState.Lines.Count > 1000 then
  TextCallState.Lines.Delete(1);

 if (State = 'IDLE') then
  begin
   CommandCall.Enabled := True;
   CommandHangUp.Enabled := False;
   Menu.Items[1].Enabled := True;
   exit;
  end;
 if (State = 'ACCEPTED') then
  begin
   CommandCall.Enabled := False;
   CommandHangUp.Enabled := True;
   Settings1.Enabled := False;
   exit;
  end;
 if (State = 'CONNECTED') then
  begin
   CommandCall.Enabled := False;
   CommandHangUp.Enabled := True;
   Settings1.Enabled := True;
   exit;
  end;
end;

procedure TfrmMain.amTapiPro1Connected(Sender: TObject);
begin
 LabelStatus.Caption := 'Connected';
end;

procedure TfrmMain.amTapiPro1DelayedError(Sender: TObject; decType: Integer;
  const Description: WideString);
begin
 case decType of
  ANSWER_ERROR: ShowMessage('Answer error. ' + Description);
  DIAL_ERROR: ShowMessage('Dialing error. ' + Description);
  GENERATE_DIGITS_ERROR: ShowMessage('Generate digits error. ' + Description);
  HANGUP_ERROR: ShowMessage('Hangup error. ' + Description);
  MAKE_CALL_ERROR: ShowMessage('Make call error. ' + Description);
 end;
end;

procedure TfrmMain.amTapiPro1DigitReceived(Sender: TObject;
  const Digit: WideString);
begin
    TextCallState.Lines.Add('Digit received ' + Digit);
end;

procedure TfrmMain.amTapiPro1Disconnected(Sender: TObject);
begin
  LabelStatus.Caption := 'Disconnected';
  amWavePro1.StopPlay;
  amWavePro1.StopRecord;
  amTapiPro1.HangUp;
  Settings1.Enabled:=true;
end;

procedure TfrmMain.amTapiPro1GenerateDigitsDone(Sender: TObject);
begin
    TextCallState.Lines.Add('Generate digits done');
end;

procedure TfrmMain.amTapiPro1Idle(Sender: TObject);
begin
 LabelStatus.Caption := 'Idle';
end;

procedure TfrmMain.amTapiPro1IncomingCall(Sender: TObject;
  RingNumber: Integer);
var RingsBeforeAnswer : integer;
begin
  LabelStatus.Caption := 'Incoming Call';
  TextCallState.Lines.Add('Ringing' + inttostr(RingNumber));

  //If auto answer
  if GetSetting('TapiProWavePro', 'Settings', 'Auto Answer', True) then
   begin
    RingsBeforeAnswer := GetSetting('TapiProWavePro', 'Settings', 'Rings Before Answer', 2);
    //This will answer after RingsBeforeAnswer rings if the user has the 'Own incoming calls' set to True
    If RingNumber >= RingsBeforeAnswer Then amTapiPro1.Answer;
   end;
end;

procedure TfrmMain.amWavePro1DonePlay(Sender: TObject);
begin
 CommandStop.Enabled := False;
 CommandPlay.Enabled := True;
 CommandRecord.Enabled := True;
end;

procedure TfrmMain.amWavePro1DoneRecord(Sender: TObject);
begin
 CommandStop.Enabled := False;
 CommandPlay.Enabled := True;
 CommandRecord.Enabled := True;
end;

procedure TfrmMain.amWavePro1Silence(Sender: TObject; Silence: WordBool);
begin
 if Silence then
  begin
     LabelSilence.Caption := 'SILENCE';
     LabelSilence.Font.Color := clBlack;
  end
 else
     LabelSilence.Caption := 'NOISE';
     LabelSilence.Font.Color := clRed;
end;

procedure TfrmMain.amWavePro1VUChange(Sender: TObject; PlayVolume,
  RecordLevel: Smallint);
begin
 ProgressBar.Position := PlayVolume + RecordLevel;
end;

procedure TfrmMain.FormShow(Sender: TObject);
begin
  CommandHangUp.Enabled := False;
  LabelStatus.Caption := 'Idle';
  amTapiPro1.MediaMode := AUTOMATEDVOICE;
  //if this is the first run of the application the line device name will not be saved
  If (GetSetting('TapiProWavePro', 'Settings', 'Line Device', 'Not Set') = 'Not Set') then
   begin
    frmSettings.ShowModal;
   end
  else
   begin
    if amTapiPro1.LineOpen then amTapiPro1.LineOpen := False;
    amTapiPro1.LineName := GetSetting('TapiProWavePro', 'Settings', 'Line Device', 'Not Set');
    amTapiPro1.CallPrivilege := OWNERCONST;
    amTapiPro1.LineOpen := True;
    TextTelephoneNumber.Text := GetSetting('TapiProWavePro', 'Settings', 'Telephone Number', '');
  end;

end;

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  amWavePro1.StopPlay;
  amWavePro1.StopRecord;
  amTapiPro1.HangUp;
  amTapiPro1.LineOpen := False;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
 PlayVol:=amWavePro1.PlayVolume;
 RecordVol:=amWavePro1.RecordLevel;
 SliderPlayVolume.Position:=(SliderPlayVolume.Max-SliderPlayVolume.Min) div 2;
 SliderRecordVolume.Position:=(SliderRecordVolume.Max-SliderRecordVolume.Min) div 2;
 amWavePro1.PlayVolume :=PlayVol;
 amWavePro1.RecordLevel:=RecordVol;
end;

end.

⌨️ 快捷键说明

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