ec_reciottdata( )
Cautions | Example | Errors | See Also
Description
The ec_reciottdata( ) function starts an echo-cancelled record to a file or memory buffer on a CSP-capable full-duplex channel.
You can perform a record at all times or a voice-activated record. To perform a voice-activated record, where recording begins only after speech energy has been detected, enable ECCH_VADINITIATED in ec_setparm( ).
Cautions
- This function fails if an unsupported data format is specified. For a list of supported data formats, see the Continuous Speech Processing API Programming Guide.
- On SpringWare boards, we recommend that you use the same data format for play and recording/streaming.
- To set the proper parameters, the ec_setparm( ) function must be called for every ec_reciottdata( ) occurrence in your application.
- If you use this function in synchronous mode, you must use multithreading in your application.
- In Linux applications that use multiple threads, you must avoid having two or more threads call functions that send commands to the same channel; otherwise, the replies can be unpredictable and cause those functions to time out. If you must do this, use semaphores to prevent concurrent access to a particular channel.
- All files specified in the DX_IOTT table are of the file format described in DX_XPB.
- All files recorded to have the data encoding and rate as described in DX_XPB.
- The DX_IOTT data area must remain in scope for the duration of the function if running asynchronously.
- The DX_XPB data area must remain in scope for the duration of the function if running asynchronously.
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 () { int chdev; /* channel descriptor */ int fd; /* file descriptor for file to be played */ DX_IOTT iott, iott1; /* I/O transfer table */ DV_TPT tpt, tpt1; /* termination parameter table */ DX_XPB xpb; /* I/O transfer parameter block */ int parmval = 1; int srlmode; /* Standard Runtime Library mode */ /* Set SRL to run in polled mode. */ srlmode = SR_POLLMODE; if (sr_setparm(SRL_DEVICE, SR_MODEID, (void *)&srlmode) == -1) { /* process error */ } . . . /* Open channel */ if ((chdev = dx_open("dxxxB1C1",0)) == -1) { /* process error */ } /* Set event mask to send the VAD events to the application */ dx_setevtmsk(chdev, DM_VADEVTS); /* To use barge-in and voice-activated recording, you must enable * ECCH_VADINITIATED (enabled by default) and DXCH_BARGEIN using * ec_setparm( ) */ ec_setparm (chdev, DXCH_BARGEIN, &parmval); ec_setparm (chdev, ECCH_VADINITIATED, &parmval); . . . /* Set up DV_TPT for record */ tpt.tp_type = IO_EOT; tpt.tp_termno = DX_MAXTIME; tpt.tp_length = 60; /* max time for record is 6 secs */ tpt.tp_flags = TF_MAXTIME; /* Open file */ #ifdef WIN32 if (( iott.io_fhandle = dx_fileopen("MESSAGE.VOX",O_RDWR| O_BINARY| O_CREAT| O_TRUNC, 0666)) == -1) { printf("File open error\n"); exit(2); } #else if (( iott.io_fhandle = open("MESSAGE.VOX",O_RDWR| O_CREAT| O_TRUNC, 0666)) == -1) { printf("File open error\n"); exit(2); } #endif /* Set up DX_IOTT */ iott.io_bufp = 0; iott.io_offset = 0; iott.io_length = -1; iott.io_type = IO_DEV | IO_EOT; /* * Specify VOX file format for PCM at 8KHz. */ xpb.wFileFormat = FILE_FORMAT_VOX; xpb.wDataFormat = DATA_FORMAT_PCM; xpb.nSamplesPerSec = DRT_8KHZ; xpb.wBitsPerSample = 8; /* Start recording. */ if (ec_reciottdata(chdev, &iott, &tpt, &xpb, EV_ASYNC | MD_NOGAIN) == -1) { printf("Error recording file - %s\n", ATDV_ERRMSGP(chdev)); exit(4); } /* Open file to be played */ #ifdef WIN32 if ((iott1.io_fhandle = dx_fileopen("SAMPLE.VOX",O_RDONLY|O_BINARY)) == -1) { printf("Error opening SAMPLE.VOX\n"); exit(1); } #else if (( iott1.io_fhandle = open("SAMPLE.VOX",O_RDONLY)) == -1) { printf("File open error\n"); exit(2); } #endif iott1.io_bufp = 0; iott1.io_offset = 0; iott1.io_length = -1; iott1.io_type = IO_DEV | IO_EOT; /* Set up DV_TPT for play */ tpt1.tp_type = IO_EOT; tpt1.tp_termno = DX_MAXDTMF; tpt1.tp_length = 1; tpt1.tp_flags = TF_MAXDTMF; /* Play intro message; use same file format as record */ if (dx_playiottdata(chdev,&iott1,&tpt1,&xpb,EV_ASYNC) == -1) { printf("Error playing file - %s\n", ATDV_ERRMSGP(chdev)); exit(4); } /* Wait for barge-in and echo-cancelled record to complete */ while (1) { sr_waitevt(-1); ret = sr_getevttype(); if (ret == TDX_BARGEIN) { printf("TDX_BARGEIN event received\n"); } else if (ret == TDX_PLAY) { printf("Play Completed event received\n"); break; } else if (ret == TEC_STREAM) { printf("TEC_STREAM - termination event"); printf("for ec_stream and ec_reciottdata received\n"); break; } else if (ret == TDX_ERROR) { printf("ERROR event received\n"); } else { printf("Event 0x%x received.\n", ret); } } /* end while */ /* Close record file */ #ifdef WIN32 if (dx_fileclose(iott.io_fhandle) == -1) { printf("Error closing MESSAGE.VOX \n"); exit(1); } #else if (close(iott.io_fhandle) == -1) { printf("Error closing MESSAGE.VOX \n"); exit(1); } #endif /* Close play file */ #ifdef WIN32 if (dx_fileclose(iott1.io_fhandle) == -1 { printf("Error closing SAMPLE.VOX \n"); exit(1); } #else if (close(iott1.io_fhandle) == -1) { printf("Error closing SAMPLE.VOX \n"); exit(1); } #endif /* Close channel */ dx_close(chdev);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:
See Also
- ec_stream( )
- dx_reciottdata( )
Click here to contact Dialogic Customer Engineering
Copyright 2001, Intel Corporation