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

📄 pansr.cpp

📁 基于dialogic语音卡的IVR系统源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	{	//* Digital Frontend 
		if (gc_Start(NULL) != GC_SUCCESS) 
		{
			ShowError("gc_Start()");
			QUIT( 2 );
		} 
		if( frontend == CT_NTE1 )  //数字卡
			chansPerBoard = 30;
		else
			chansPerBoard = 24;

		GetPrivateProfileString("CHANNEL", "INBOUND", "", paramstr, 60, ".\\Setup.ini" );
		GetParams( paramstr, bgnCh, endCh , protocol ); 
		
		rc = OpenGloalDev( bgnCh, endCh, protocol, 1, chansPerBoard );
		if ( rc < 0 ) QUIT( 2 );

		//* Route timeslots to channels based upon bus mode.
		for ( channum = bgnCh; channum <= endCh; channum++ )
		{
			if (scbus == TRUE)
			{
			//	RouteForVox( channum );
			}
			
			rc = gc_SetEvtMsk( dxinfo[ channum ].g_dev, GCMSK_BLOCKED|GCMSK_UNBLOCKED,GCACT_ADDMSK);
			if (rc != GC_SUCCESS)  
			{
				ShowError("gc_SetEvtMsk()");
				QUIT(2);
			}

			dxinfo[ channum ].state = ST_WTRING;

			if (SendMessage(hWnd, WM_DLGC_STATE, channum, ST_WTRING) == -1)
			{
				MessageBox(NULL, "Send Message Hook State Failed.", 
						"Error", MB_ICONEXCLAMATION);
				QUIT(2);
			}
		}// ends the for loop--!

		GetPrivateProfileString("CHANNEL", "OUTBOUND", "", paramstr, 60, ".\\Setup.ini" );
		GetParams( paramstr, bgnCh, endCh , protocol ); 

		rc = OpenGloalDev( bgnCh, endCh, protocol, 2, chansPerBoard );
		if ( rc < 0 ) QUIT( 2 );
		//* Route timeslots to channels based upon bus mode.
		for ( channum = bgnCh; channum <= endCh; channum++ )
		{
			if (scbus == TRUE)
			{
			//	RouteForVox( channum );
			}
			
			rc = gc_SetEvtMsk( dxinfo[ channum ].g_dev, GCMSK_BLOCKED|GCMSK_UNBLOCKED,GCACT_ADDMSK);
			if (rc != GC_SUCCESS)  
			{
				ShowError("gc_SetEvtMsk()");
				QUIT(2);
			}

			dxinfo[ channum ].state = ST_WTRING;

			if (SendMessage(hWnd, WM_DLGC_STATE, channum, ST_WTRING) == -1)
			{
				MessageBox(NULL, "Send Message Hook State Failed.", 
						"Error", MB_ICONEXCLAMATION);
				QUIT(2);
			}
		}// ends the for loop--!
	} 
	
	// Open fax channels
	for ( channum = 1; channum <= faxchans; channum++ )
	{
		sprintf( d4xname, "dxxxB%dC%d",
				(channum % 4) ? (channum / 4) + faxbdnum :
				(channum / 4)+faxbdnum - 1,
				(channum % 4) ? (channum % 4) : 4 );

		if ( ( fxinfo[ channum ].fxdev = fx_open( d4xname, NULL) ) == -1 )
		{
			sprintf( tmpbuff, "Unable to open channel %s, errno = %d",
					d4xname, dx_fileerrno() );
			disp_msg( tmpbuff );
			QUIT( 2 );
		}
		fxinfo[ channum ].status = 0;
	} 
	// Ends of fax channel open

	MsiInit();
}

int  DialOut( int channum )
{
	dxinfo[ channum ].ac_count--; 
	if( dxinfo[ channum ].ac_count < 0 ) return -1;
	dx_clrcap( &(dxinfo[ channum ].capp) );
	dxinfo[ channum ].capp.ca_nbrdna = 8;
	return( dx_dial(dxinfo[ channum ].chdev,dxinfo[ channum ].dnis_buf,
		&(dxinfo[ channum ].capp),DX_CALLP|EV_ASYNC) ) ;
}

int PlayDtmfTone( int channum )
{
	dx_clrdigbuf( dxinfo[ channum ].chdev );

	//* Clear and Set-Up the IOTT strcuture
	memset( dxinfo[ channum ].iott, 0, 45*sizeof( DX_IOTT ) );

	dxinfo[ channum ].iott[ 0 ].io_type = IO_MEM | IO_EOT;
	dxinfo[ channum ].iott[ 0 ].io_bufp = dxinfo[ channum ].msg_buf;
	dxinfo[ channum ].iott[ 0 ].io_offset = 0;
	dxinfo[ channum ].iott[ 0 ].io_length = dxinfo[ channum ].msg_len;

    //* Play VOX File on D/4x Channel, Normal Play Back
	return dx_play(dxinfo[ channum ].chdev, dxinfo[ channum ].iott, NULL, EV_ASYNC | PM_SR8);
}

//以厘秒为单位播放静音
int PlaySilence( int channum, int centisecond )
{
	dx_clrdigbuf( dxinfo[ channum ].chdev );

	//* Clear and Set-Up the IOTT strcuture
	memset( dxinfo[ channum ].iott, 0, 45*sizeof( DX_IOTT ) );
	
	dxinfo[ channum ].msg_buf = new char[centisecond *4];
	memset( dxinfo[ channum ].msg_buf, 0x80, centisecond *4 );
	dxinfo[ channum ].msg_len = centisecond *4;
	
	dxinfo[ channum ].iott[ 0 ].io_type = IO_MEM | IO_EOT;
	dxinfo[ channum ].iott[ 0 ].io_bufp = dxinfo[ channum ].msg_buf;
	dxinfo[ channum ].iott[ 0 ].io_offset = 0;
	dxinfo[ channum ].iott[ 0 ].io_length = dxinfo[ channum ].msg_len;

    //* Play VOX File on D/4x Channel, Normal Play Back
	return dx_play(dxinfo[ channum ].chdev, dxinfo[ channum ].iott, NULL, EV_ASYNC | PM_SR8);
}

int PlayInfoTone(int channum)
{
	char dtmf ;
	
	if( dxinfo[ channum ].ac_count <= 0 ) return 0;

	dtmf = *(dxinfo[ channum ].ac_infotone+dxinfo[ channum ].ac_point);

	dxinfo[ channum ].ac_count--;
	++dxinfo[ channum ].ac_point;

	return PlayDTMF( channum, dtmf );
}

int PlayMsg(int channum)
{
	int errcode=0, maxdigs=1, isclear=1;
	VOCINFO *p=dxinfo[ channum ].ac_voice+dxinfo[ channum ].ac_point;

	if( dxinfo[ channum ].ac_count <= 0 ) return 0;

	isclear = dxinfo[ channum ].bIsClear;
	
	if( dxinfo[ channum ].service == CMD_PLAY1 || dxinfo[ channum ].service == CMD_PLAY4 ) 
		maxdigs = 0; 
	else
		maxdigs = 1;
	
	maxdigs = 1;
	dxinfo[ channum ].ac_count--;
	++dxinfo[ channum ].ac_point;
	
	if( dxinfo[ channum ].service == CMD_PLAYINFOTONE )
	{
		if( dxinfo[ channum ].bIsInfotone == FALSE )
		{
			dxinfo[ channum ].ac_count = 0;
			dxinfo[ channum ].ac_point = 0;
			delete dxinfo[ channum ].ac_voice;
			dxinfo[ channum ].ac_voice = NULL;
			WriteReplyQueue( channum, TDX_PLAYTONE );
			return 0;
		}
		dxinfo[ channum ].msg_len = GeneDtmfTone( p->Content, &dxinfo[ channum ].msg_buf );
		errcode = PlayDtmfTone( channum );
		return errcode;
	}

	if (p->Kind=='0')	
	{			
		//add by lj 2003/06/23
		if( strlen( dxinfo[ channum ].msg_path ) > 0 )
		{
			if(memcmp(p->Content, "sz", 2) ==0)
				BuildName( channum, "d:\\Pvoc12\\lmvoc\\share", p->Content);
			else
				BuildName( channum, dxinfo[ channum ].msg_path, p->Content);
		}
		else
			BuildName( channum, SVocDir, p->Content);
		errcode = PlayFile( channum, dxinfo[ channum ].msg_name, maxdigs, isclear );
	}
	else
	{
		errcode = PlayComb( channum, p->Content, maxdigs, isclear );
	}
	return errcode;
}

/***************************************************************************
 *        NAME: int PlayFile( channum, voicefile, maxdigs, isclear )
 * DESCRIPTION: Set up IOTT and TPT's and Initiate the Play-Back
 *       INPUT: int  channum;     - Index into dxinfo structure
 *				char *voicefile;  - VOX file name to Play-Back
 *              int  maxdigs;     - How many digs pressed to stop play
 *				int  isclear;     - Whether clear digbuf or not
 *      OUTPUT: Starts the play-back
 *     RETURNS: -1 = Error
 *				0 = Success
 *    CAUTIONS: None
 ***************************************************************************/
int PlayFile(int channum, char * voicefile, int maxdigs, BOOL isclear)
{
	int filedesc, memplay=0;
	
	if( isclear ) dx_clrdigbuf( dxinfo[ channum ].chdev );

	if( access(voicefile, 0) != 0 )
	{
		sprintf( tmpbuff, "Cannot open %s", voicefile );
		wprintf_err1( "%s", tmpbuff );
		memplay = 1;
	}
	else
	{
		if((filedesc = dx_fileopen( voicefile, O_RDONLY|O_BINARY, 0666)) == -1)
		{
			sprintf( tmpbuff, "Cannot open %s", voicefile );
			disp_msg(tmpbuff);
		}
		
		if (dx_fileseek( filedesc, 0, SEEK_SET ) == -1 )
		{
			sprintf( tmpbuff, "%s Cannot seek to the beginning of the VOX file",
				ATDV_NAMEP( dxinfo[ channum ].chdev ) );
			disp_msg( tmpbuff );
		}
	}

	//* Clear and Set-Up the IOTT strcuture
	memset( dxinfo[ channum ].iott, 0, 45*sizeof( DX_IOTT ) );
	
	if( memplay )
	{
		dxinfo[ channum ].msg_fd = 0; 
		dxinfo[ channum ].iott[ 0 ].io_type = IO_MEM | IO_EOT;
		dxinfo[ channum ].iott[ 0 ].io_bufp = pSilenceBuf;
		dxinfo[ channum ].iott[ 0 ].io_offset = 0;
		dxinfo[ channum ].iott[ 0 ].io_length = 8000;
	}
	else
	{
		dxinfo[ channum ].msg_fd = filedesc; 
		dxinfo[ channum ].iott[0].io_type = IO_DEV | IO_EOT;
		dxinfo[ channum ].iott[0].io_fhandle = filedesc;
		dxinfo[ channum ].iott[0].io_length = -1;
	}
	
	//* Clear and then Set the DV_TPT structures
	dx_clrtpt( dxinfo[ channum ].tpt, 4);
	
	dxinfo[ channum ].tpt[ 0 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 1 ].tp_type = IO_EOT;

	//* Terminate Play on Receiving any DTMF tone 
	dxinfo[ channum ].tpt[ 0 ].tp_termno = DX_MAXDTMF;
	dxinfo[ channum ].tpt[ 0 ].tp_length = maxdigs;
	dxinfo[ channum ].tpt[ 0 ].tp_flags  = TF_MAXDTMF;

	//* Terminate Play on Loop Current Drop 
	dxinfo[ channum ].tpt[ 1 ].tp_termno = DX_LCOFF;
	dxinfo[ channum ].tpt[ 1 ].tp_length = 1;
	dxinfo[ channum ].tpt[ 1 ].tp_flags  = TF_LCOFF;

    //* Play VOX File on D/4x Channel, Normal Play Back
	return dx_play(dxinfo[ channum ].chdev, dxinfo[ channum ].iott, dxinfo[ channum ].tpt, EV_ASYNC | MD_ADPCM | PM_SR8);
	//return dx_play(dxinfo[ channum ].chdev, dxinfo[ channum ].iott, NULL, EV_ASYNC | MD_ADPCM | PM_SR8);
}

/********************************************************************
 * 播放组合音                                                       *    
 ********************************************************************/
int PlayComb(int channum, char * voicecomb, int maxdigs, BOOL isclear)
{
	int i, j, len , lang, iFlag;
	char Note[21] = "";

	if( isclear ) dx_clrdigbuf( dxinfo[ channum ].chdev );

	lang = dxinfo[ channum ].language ;

	//* Clear and Set-Up the IOTT strcuture
	memset( dxinfo[ channum ].iott, 0, 45*sizeof( DX_IOTT ) );

	if( lang != 2 ) //普通话及粤语
	{
		len = strlen( voicecomb );
		if( len<1 ) len=1;
		if( len>45 ) len=45;
		for( i=0; i<len; i++ )
		{
			for ( j=0; j<CombCount[lang]; j++)
			{
				if ( pCombIdx[lang][j].Id == voicecomb[i] )
					break;
			}
			if( j==CombCount[lang] ) j=0;
			dxinfo[ channum ].iott[ i ].io_type = IO_MEM;
			dxinfo[ channum ].iott[ i ].io_bufp =   pCombBuf[lang];
			dxinfo[ channum ].iott[ i ].io_offset = pCombIdx[lang][j].Offset;
			dxinfo[ channum ].iott[ i ].io_length = pCombIdx[lang][j].Length;
		}
		dxinfo[ channum ].iott [ len-1 ].io_type = IO_MEM | IO_EOT;	
	}
	else
	{
		len = 1;
		while(1)
		{
			iFlag = CVSInterpreter::AbstractData( voicecomb, len, Note, ',' );
			if( iFlag != 0 && len>1 ) break;
			if( strlen(Note) == 0 ) break;
			for ( j=0; j<CombCount[lang]; j++)
			{
				if ( stricmp(pCombIdx[lang][j].Note, Note) == 0 )
					break;
			}
			if( j==CombCount[lang] ) j=0;
			dxinfo[ channum ].iott[ len-1 ].io_type = IO_MEM;
			dxinfo[ channum ].iott[ len-1 ].io_bufp =   pCombBuf[lang];
			dxinfo[ channum ].iott[ len-1 ].io_offset = pCombIdx[lang][j].Offset;
			dxinfo[ channum ].iott[ len-1 ].io_length = pCombIdx[lang][j].Length;
			len++;
		}
		len--;

		dxinfo[ channum ].iott [ len-1 ].io_type = IO_MEM | IO_EOT;	
	}
	
	//* Clear and then Set the DV_TPT structures
	dx_clrtpt( dxinfo[ channum ].tpt, 4);
	dxinfo[ channum ].tpt[ 0 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 1 ].tp_type = IO_EOT;

	//* Terminate Play on Receiving any DTMF tone 
	dxinfo[ channum ].tpt[ 0 ].tp_termno = DX_MAXDTMF;
	dxinfo[ channum ].tpt[ 0 ].tp_length = maxdigs;
	dxinfo[ channum ].tpt[ 0 ].tp_flags  = TF_MAXDTMF;

	//* Terminate Play on Loop Current Drop 
	dxinfo[ channum ].tpt[ 1 ].tp_termno = DX_LCOFF;
	dxinfo[ channum ].tpt[ 1 ].tp_length = 1;
	dxinfo[ channum ].tpt[ 1 ].tp_flags  = TF_LCOFF;

    //* Play VOX File on D/4x Channel, Normal Play Back
	return dx_play(dxinfo[ channum ].chdev, dxinfo[ channum ].iott, dxinfo[ channum ].tpt, EV_ASYNC | MD_ADPCM | PM_SR8);
}

/***************************************************************************
 *        NAME: int get_digits( channum, digbufp, maxdigs, maskdig, maxtime)
 * DESCRIPTION: Set up TPT's and Initiate get-digits function
 *       INPUT: int channum;        - Index into dxinfo structure
 *              DV_DIGIT *digbufp;  - Pointer to Digit Buffer
 *				int maxdigs         - How many digs to receive
 *				int maskdig         - Specific digits to stop
 *				int maxtime         - Maxtime to wait 
 *      OUTPUT: Starts to get the DTMF Digits
 *     RETURNS: -1 = Error
 *		         0 = Success
 *    CAUTIONS: None
 ***************************************************************************/
int get_digits(int channum, DV_DIGIT *digbufp , int maxdigs, int maskdig, 
			   int maxtime )
{
	//* Clear and then Set the DV_TPT structures
    
	memset( dxinfo[ channum ].tpt, 0, (sizeof( DV_TPT ) * 4) );

	//* Terminate GetDigits on Receiving maxdigs Digits 
	dxinfo[ channum ].tpt[ 0 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 0 ].tp_termno = DX_MAXDTMF;
	dxinfo[ channum ].tpt[ 0 ].tp_length = maxdigs;
	dxinfo[ channum ].tpt[ 0 ].tp_flags = TF_MAXDTMF;

	//* Terminate GetDigits on Loop Current Drop 
	dxinfo[ channum ].tpt[ 1 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 1 ].tp_termno = DX_LCOFF;
	dxinfo[ channum ].tpt[ 1 ].tp_length = 1;
	dxinfo[ channum ].tpt[ 1 ].tp_flags = TF_LCOFF;

	//* Terminate GetDigits after a specific digits pressed
	dxinfo[ channum ].tpt[ 2 ].tp_type = IO_CONT;
	dxinfo[ channum ].tpt[ 2 ].tp_termno = DX_DIGMASK;
	dxinfo[ channum ].tpt[ 2 ].tp_length = maskdig;
	dxinfo[ channum ].tpt[ 2 ].tp_flags = TF_DIGMASK;

	//* Terminate GetDigits after specific timeout
	dxinfo[ channum ].tpt[ 3 ].tp_type = IO_EOT;
	dxinfo[ channum ].tpt[ 3 ].tp_termno = DX_MAXTIME;
	dxinfo[ channum ].tpt[ 3 ].tp_length = maxtime;
	dxinfo[ channum ].tpt[ 3 ].tp_flags = TF_MAXTIME;

	return( dx_getdig( dxinfo[ channum ].chdev, dxinfo[ channum ].tpt, digbufp, EV_ASYNC ) );
}

/***************************************************************************
 *        NAME: int RecordFile( int channum, int maxtime )
 * DESCRIPTION: Set up IOTT and TPT's and Initiate the record
 *       INPUT: int channum;	- Index into dxinfo structure
 *				int maxtime;	- Maxtime to Record 
 *      OUTPUT: Starts the Recording
 *     RETURNS: -1 = Error
 *		 0 = Success
 *    CAUTIONS: None
 ***************************************************************************/
int RecordFile( int channum, int maxtime )
{	
	char  filename[128];
	
	strcpy( filename, dxinfo[channum].msg_name );
	
	BuildName1( channum, GVocDir, filename );
	
	dxinfo[channum].msg_fd =
				dx_fileopen( dxinfo[channum].msg_name, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0666 );
        
	if (dxinfo[ channum ].msg_fd == -1)
	{
		sprintf( tmpbuff, "Cannot create %s for recording", dxinfo[ channum ].msg_name );

⌨️ 快捷键说明

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