?? unit1.~pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AdTapi, OoMisc, AdPort, ExtCtrls;
type
TForm1 = class(TForm)
ApdComPort1: TApdComPort;
ApdTapiDevice1: TApdTapiDevice;
LBSysInfo: TListBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ApdTapiDevice1TapiConnect(Sender: TObject);
procedure ApdTapiDevice1TapiDTMF(CP: TObject; Digit: Char;
ErrorCode: Integer);
procedure ApdTapiDevice1TapiWaveNotify(CP: TObject; Msg: TWaveMessage);
procedure Timer1Timer(Sender: TObject);
procedure clickk;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CurrentState:(csIdle,csWaiting,csConnected,csPlaying, csRecording,sDisconnected);
implementation
{$R *.dfm}
procedure TForm1.clickk;
begin
ApdTapiDevice1.CancelCall;
LBSysInfo.Items.Add('掛斷對方電話');
CurrentState := csIdle;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ApdTapiDevice1.EnableVoice := True;
except
Application.MessageBox('當前設備不支持語音擴展', '錯誤', MB_OK);
end;
if ApdTapiDevice1.EnableVoice then
begin
ApdTapiDevice1.AutoAnswer;
LBSysInfo.Items.Add('設備就緒可接聽對方電話');
CurrentState := csWaiting;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ApdTapiDevice1.SelectDevice;
ApdTapiDevice1.EnableVoice := True;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
// ApdTapiDevice1.PlayWaveFile('.\Ring.WAV');
ApdTapiDevice1.CancelCall;
LBSysInfo.Items.Add('掛斷對方電話');
CurrentState := csIdle;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CurrentState := csIdle;
ApdTapiDevice1.TrimSeconds := 5; //錄音時有5秒靜音就掛斷
end;
procedure TForm1.ApdTapiDevice1TapiConnect(Sender: TObject);
begin
CurrentState := csConnected;
LBSysInfo.Items.Add(':連接成功');
ApdTapiDevice1.PlayWaveFile('Welcome.wav');//播放功能提示語音
LBSysInfo.Items.Add(':播放Ring.WAV');
end;
procedure TForm1.ApdTapiDevice1TapiDTMF(CP: TObject; Digit: Char;
ErrorCode: Integer);
var
strr:string;
begin
if (Digit ='') or (Digit = '') then
Exit;
strr:=strr+Digit;
LBSysInfo.Items.Add('dtmf:按鍵='+ strr);
//CurrentCommand:=CurrentCommand Digit;
{簡單狀態機}
if strr<>'' then
begin
if strr = '*#' then
begin
//CurrentCommand := '';
ApdTapiDevice1.MaxMessageLength := 30; //最長記錄時間30秒
ApdTapiDevice1.InterruptWave := False; //按鍵不能中斷提示語音的播放
ApdTapiDevice1.PlayWaveFile('Welcome.wav');//播放錄音提示語音
CurrentState := csRecording;
LBSysInfo.Items.Add('luyingzhubei');
Exit;
end;
if Digit='1' then
begin
ApdTapiDevice1.PlayWaveFile('play1.wav');
LBSysInfo.Items.Add(Format('%s %s 正在播放 %s',[ApdTapiDevice1.calleridname, apdtapidevice1.callerid,'play1.wav']));
end
else
begin
//播放錯誤提示語音,并要求用戶重新輸入命令
ApdTapiDevice1.PlayWaveFile('Greeting.wav');
LBSysInfo.Items.Add(Format('%s %s 輸入了錯誤的號碼',[ApdTapiDevice1.calleridname, apdtapidevice1.callerid]));
end;
//重置命令為空
//CurrentCommand := '';
end;
end;
procedure TForm1.ApdTapiDevice1TapiWaveNotify(CP: TObject;
Msg: TWaveMessage);
var
//TimeStr: string;
FileName: string;
begin
//決不能在case外做耗時的操作
case Msg of
waPlayOpen: LBSysInfo.Items.Add('wavnotify:播放開始');
waPlayDone:
begin
LBSysInfo.Items.Add('wavnotify:播放結束');
if CurrentState = csRecording then
begin
try
while ApdTapiDevice1.WaveState <> wsIdle do
Application.ProcessMessages;
ApdTapiDevice1.InterruptWave := True;
ApdTapiDevice1.StartWaveRecord;
LBSysInfo.Items.Add('dtmf:錄音成功');
except
LBSysInfo.Items.Add('dtmf:錄音失敗');
end;
end;
end;
waPlayClose: LBSysInfo.Items.Add('wavnotify:播放關閉');
waRecordOpen: LBSysInfo.Items.Add('wavnotify:錄音開始');
waDataReady:
begin
LBSysInfo.Items.Add('wavnotify:數據準備');
TimeSeparator := '-';
FileName := DateTimeToStr(Now)+ '.wav';
try
ApdTapiDevice1.SaveWaveFile(ExtractFilePath(ParamStr(0)) +FileName, True);
LBSysInfo.Items.Add('wavNotify:保存聲音文件 '+ FileName);
except
LBSysInfo.Items.Add('wavnotify:保存聲音文件失敗');
end;
end;
waRecordClose:
LBSysInfo.Items.Add('wavnotify:記錄聲音結束');
//CurrentState:= csWaiting;
//ActionCancelExecute(nil);
//timer1.
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
clickk;
//CurrentState := csWaiting;
//Timer1.Enabled := False;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -