用C++写的一段电话录音程序代码
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <MPlayer.hpp>
#include "exam1.h"
#include "swind.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormExam *FormExam;
int LineCount;
int LineStatus[8];
//---------------------------------------------------------------------------
__fastcall TFormExam::TFormExam(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormExam::FormShow(TObject *Sender)
{
SW_Init();
SW_SetType(1);//设置设备类型
LineCount=SW_GetCount();
Label6->Caption="共"+IntToStr(LineCount)+"线";
Timer1->Enabled=true;
for (int i=0;i<LineCount;i++)
LineStatus[i]=0; //线路状态
}
//---------------------------------------------------------------------------
void __fastcall TFormExam::FormClose(TObject *Sender, TCloseAction &Action)
{
SW_Free();
}
//---------------------------------------------------------------------------
void __fastcall TFormExam::Timer1Timer(TObject *Sender)
{
AnsiString s1;
char buf[16];
int i;
//本程序的处理流程
//1。判断是否摘机,检测是否收到CID来电号码
//2。若摘机,开始文件录音,并检测是否收到DTMF号码
//3。 判断是否挂机
//4。 若挂机,停止文件录音,开始下一个循环处理
LineCount=SW_GetCount();
for (int line=0;line<LineCount;line++)
{
if (LineStatus[line]==0)
{
//摘机处理
i = SW_CheckOffHook(line);
if (i==-1)
{
Edit1->Text = "检查USB电话录音盒是否安装!";
return;
}
if (i==1)
{
Edit1->Text = "线"+IntToStr(line)+":"+"电话摘机!";
i=SW_StartFileRecord(line,Edit4->Text.c_str(),0xffffff);
if (i==-1)
{
Edit1->Text = "文件录音出错!";
return;
}
Edit1->Text ="线"+IntToStr(line)+":"+"正在录音...";
Button2->Enabled=false;
LineStatus[line]=1;
}
//收到CID处理
i=SW_ReceiveCID(line,buf);
if (i==-1)
{
Edit2->Text = "检查USB电话录音盒是否安装!";
return;
}
else
if (i!=0)
{
s1=buf;
Edit2->Text = "线"+IntToStr(line)+":"+s1.Trim();
}
}
if (LineStatus[line]==1)
{
i=SW_ReceiveDTMF(line,buf);
if (i==-1)
{
Edit3->Text = "检查USB电话录音盒是否安装!";
return;
}
else
if (i!=0)
{
s1=buf;
Edit3->Text ="线"+IntToStr(line)+":"+s1.Trim();
}
long ls1=SW_CheckFileRecordEnd(line);
if (ls1== -1l )
{
Edit1->Text = "检查USB电话录音盒是否安装!";
return;
}
if (ls1== 0l )
{
SW_StopFileRecord(line);
}
//挂机处理
i = SW_CheckOffHook(line);
if (i==-1)
{
Edit1->Text = "检查USB电话录音盒是否安装!";
return;
}
if (i==0)
{
i =SW_StopFileRecord(line);
if (i==-1)
{
Edit1->Text = "检查USB电话录音盒是否安装!";
return;
}
Edit1->Text = "线"+IntToStr(line)+": 电话挂机,停止录音!";
Button2->Enabled=true;
LineStatus[line]=0;
} // end 挂机
} // end 1
} // end for
}