ec_rearm( )
Name: int ec_rearm(chDev) Inputs: int chDev Returns: 0 for success -1 for failure Includes: srllib.h dxxxlib.h eclib.h Category: I/O Mode: synchronous Description
The ec_rearm( ) function temporarily stops streaming of echo-cancelled data from the board and rearms or re-enables the voice activity detector (VAD). The prompt is not affected by this function.
If a VAD event is received and the recognizer determines that the energy was non-speech such as a cough, use this function to re-activate the VAD for the next burst of energy.
- Note: The ec_rearm( ) function is intended to be used with VAD enabled and barge-in disabled.
Parameter
Description
chDev The channel device handle obtained when the CSP-capable device is opened using dx_open( ). The following scenario describes how the ec_rearm( ) function works:
Caution: During the time that the VAD is being rearmed, you will not get a VAD event if an energy burst comes in. The time it takes for the VAD to be rearmed varies depending on hardware and operating system used.
- After the VAD is triggered, it starts streaming data to the host application.
- The host application determines that this is a false trigger and calls the ec_rearm( ) function.
- Streaming is halted and the VAD is rearmed for the next burst of energy.
Figure2-1 illustrates the rearming concept.
Figure 2-1. Rearming the Voice Activity Detector (VAD)
Example
#include <windows.h> /* include in Windows applications only; exclude in Linux */ #include <stdio.h> #include <srllib.h> #include <dxxxlib.h> #include <eclib.h> #include <errno.h> /* include in Linux applications only; exclude in Windows */ main() { char csp_devname[9]; int ret, csp_dev, parmval=0; SC_TSINFO sc_tsinfo; /* Time slot information structure */ long scts; /* SCbus time slot */ int srlmode; /* Standard Runtime Library mode */ DX_IOTT iott; /* I/O transfer table */ DV_TPT tptp[1], tpt; /* termination parameter table */ DX_XPB xpb; /* I/O transfer parameter block */ /* Set SRL to run in polled mode. */ srlmode = SR_POLLMODE; if (sr_setparm(SRL_DEVICE, SR_MODEID, (void *)&srlmode) == -1) { /* process error */ } sprintf(csp_devname,"dxxxB1C1"); /* Open a voice device. */ csp_dev = dx_open(csp_devname, 0); if (csp_dev < 0) { printf("Error %d in dx_open()\n",csp_dev); exit(-1); } /* Set up ec parameters as needed. * ECCH_VADINITIATED is enabled by default. * Barge-in should be disabled (DXCH_BARGEIN=0) so that prompt * continues to play after energy is detected. */ ret = ec_setparm( ... ); if (ret == -1) { printf("Error in ec_setparm(). Err Msg = %s, Lasterror = %d\n", ATDV_ERRMSGP(csp_dev), ATDV_LASTERR(csp_dev)); } /* Set up DV_TPT for record */ tpt.tp_type = IO_EOT; tpt.tp_termno = DX_MAXTIME; tpt.tp_length = 60; tpt.tp_flags = TF_MAXTIME; /* Record data format set to 8-bit Dialogic PCM, 8KHz sampling rate */ xpb.wFileFormat = FILE_FORMAT_VOX; xpb.wDataFormat = DATA_FORMAT_PCM; xpb.nSamplesPerSec = DRT_8KHZ; xpb.wBitsPerSample = 8; ret = ec_stream(csp_dev, &tpt, &xpb, &stream_cb, EV_ASYNC | MD_NOGAIN); if (ret == -1) { printf("Error in ec_reciottdata(). Err Msg = %s, Lasterror = %d\n", ATDV_ERRMSGP(csp_dev), ATDV_LASTERR(csp_dev)); } /* Set channel off-hook */ ret = dx_sethook(csp_dev, DX_OFFHOOK, EV_SYNC); if (ret == -1) { printf("Error in dx_sethook(). Err Msg = %s, Lasterror = %d\n", ATDV_ERRMSGP(csp_dev), ATDV_LASTERR(csp_dev)); } /* Set up DX_IOTT */ iott.io_type = IO_DEV|IO_EOT; iott.io_bufp = 0; iott.io_offset = 0; iott.io_length = -1; /* Set up DV_TPT for play */ dx_clrtpt(&tptp,1); tptp[0].tp_type = IO_EOT; tptp[0].tp_termno = DX_MAXDTMF; tptp[0].tp_length = 1; tptp[0].tp_flags = TF_MAXDTMF; /* Open file to be played */ #ifdef WIN32 if ((iott.io_fhandle = dx_fileopen("sample.vox",O_RDONLY|O_BINARY)) == -1) { printf("Error opening sample.vox.\n"); exit(1); } #else if (( iott.io_fhandle = open("sample.vox",O_RDONLY)) == -1) { printf("File open error\n"); exit(2); } #endif /* Play prompt message. */ ret = dx_play(csp_dev, &iott, &tptp, EV_ASYNC); if ( ret == -1) { printf("Error playing sample.vox.\n"); exit(1); } /* In the ASR engine section -- pseudocode */ while (utterance is undesirable) { /* Wait for TEC_VAD event */ while (TEC_VAD event is not received) { sr_waitevt(-1); ret = sr_getevttype( ); if (ret == TEC_VAD) { /* After TEC_VAD event is received, determine if utterance is desirable */ if (utterance is undesirable) { /* Use ec_rearm( ) to pause streaming and rearm the VAD trigger*/ ret = ec_rearm(csp_dev); if (ret == -1) { printf("Error in ec_rearm(). Err Msg = %s, Lasterror = %d\n", ATDV_ERRMSGP(csp_dev), ATDV_LASTERR(csp_dev)); } /* end if (ret == -1) */ } /* end if (utterance is undesirable) */ } /* end if (ret == TEC_VAD) */ } /* end while (TEC_VAD event not received) } /* end while (utterance is undesirable) */ . . .Errors
If the function returns -1, use ATDV_LASTERR( ) to return the error code and ATDV_ERRMSGP( ) to return a descriptive error message.
One of the following error codes may be returned:
Error code
Reason
EDX_BADDEV Device handle is NULL or invalid. EDX_BADPARM Parameter is invalid. EEC_UNSUPPORTED Device handle is valid but device does not support CSP.
Click here to contact Dialogic Customer Engineering
Copyright 2001, Intel Corporation