private static extern int dx_reciottdata(int ChDev, ref DX_IOTT iottp, ref DV_TPT tptp, ref DX_XPB xpbp, ushort mode);
/// <summary> /// Record a vox or wav file. /// </summary> /// <param name="devh">The handle for the Dialogic line.</param> /// <param name="filename">The name of the file to play.</param> /// <param name="terminators">Terminator keys</param> /// <param name="xpb">The format of the vox or wav file.</param> /// <param name="timeoutMilli">Number of milliseconds before timeout</param> internal static void RecordToFile(int devh, string filename, string terminators, DX_XPB xpb, int timeoutMilli) { FlushDigitBuffer(devh); /* set up DV_TPT */ var tpt = GetTerminationConditions(1, terminators, timeoutMilli); var iott = new DX_IOTT { io_type = IO_DEV | IO_EOT, io_bufp = null, io_offset = 0, io_length = -1 }; /* set up DX_IOTT */ if ((iott.io_fhandle = dx_fileopen(filename, _O_CREAT | _O_BINARY | _O_RDWR, _S_IWRITE)) == -1) { var fileErr = dx_fileerrno(); var err = ""; switch (fileErr) { case EACCES: err = "Tried to open read-only file for writing, file's sharing mode does not allow specified operations, or given path is directory."; break; case EEXIST: err = "_O_CREAT and _O_EXCL flags specified, but filename already exists."; break; case EINVAL: err = "Invalid oflag or pmode argument."; break; case EMFILE: err = "No more file descriptors available (too many open files)."; break; case ENOENT: err = "File or path not found."; break; } dx_fileclose(iott.io_fhandle); throw new VoiceException(err); } /* Now record the file */ if (dx_reciottdata(devh, ref iott, ref tpt[0], ref xpb, RM_TONE | EV_ASYNC) == -1) { var err = ATDV_ERRMSGP(devh); dx_fileclose(iott.io_fhandle); throw new VoiceException(err); } var handler = 0; while (true) { if (sr_waitevtEx(ref devh, 1, -1, ref handler) == -1) { var err = ATDV_ERRMSGP(devh); dx_fileclose(iott.io_fhandle); throw new VoiceException(err); } if (dx_fileclose(iott.io_fhandle) == -1) { var err = ATDV_ERRMSGP(devh); throw new VoiceException(err); } var type = sr_getevttype((uint)handler); if (type == TDX_RECORD) { var reason = ATDX_TERMMSK(devh); if ((reason & TM_ERROR) == TM_ERROR) { throw new VoiceException("TM_ERROR"); } if ((reason & TM_USRSTOP) == TM_USRSTOP) { throw new StopException(); } if ((reason & TM_LCOFF) == TM_LCOFF) { throw new HangupException(); } if ((reason & TM_MAXTIME) == TM_MAXTIME) { Console.WriteLine("TM_MAXTIME"); } if ((reason & TM_BARGEIN) == TM_BARGEIN) { Console.WriteLine("TM_BARGEIN"); } if ((reason & TM_DIGIT) == TM_DIGIT) { Console.WriteLine("TM_DIGIT"); } if ((reason & TM_EOD) == TM_EOD) { Console.WriteLine("TM_EOD"); } if ((reason & TM_IDDTIME) == TM_IDDTIME) { Console.WriteLine("TM_IDDTIME"); } if ((reason & TM_MAXDATA) == TM_MAXDATA) { Console.WriteLine("TM_MAXDATA"); } if ((reason & TM_MAXDTMF) == TM_MAXDTMF) { Console.WriteLine("TM_MAXDTMF"); } if ((reason & TM_MAXNOSIL) == TM_MAXNOSIL) { Console.WriteLine("TM_MTAXNOSIL"); } if ((reason & TM_MAXSIL) == TM_MAXSIL) { Console.WriteLine("TM_MAXSIL"); } if ((reason & TM_NORMTERM) == TM_NORMTERM) { Console.WriteLine("TM_NORMTERM"); } if ((reason & TM_PATTERN) == TM_PATTERN) { Console.WriteLine("TM_PATTERN"); } if ((reason & TM_TONE) == TM_TONE) { Console.WriteLine("TM_TONE"); } } else { Console.WriteLine("got here: " + type); } FlushDigitBuffer(devh); return; } }
private static extern int dx_play(int ChDev, ref DX_IOTT iottp, ref DV_TPT tptp, ushort mode);
/// <summary> /// Play a vox or wav file. /// </summary> /// <param name="devh">The handle for the Dialogic line.</param> /// <param name="filename">The name of the file to play.</param> /// <param name="terminators">Terminator keys</param> /// <param name="xpb">The format of the vox or wav file.</param> internal static void PlayFile(int devh, string filename, string terminators, DX_XPB xpb) { /* set up DV_TPT */ var tpt = GetTerminationConditions(10, terminators, 0); var iott = new DX_IOTT { io_type = IO_DEV | IO_EOT, io_bufp = null, io_offset = 0, io_length = -1 }; /* set up DX_IOTT */ if ((iott.io_fhandle = dx_fileopen(filename, _O_RDONLY | _O_BINARY)) == -1) { var fileErr = dx_fileerrno(); var err = ""; switch (fileErr) { case EACCES: err = "Tried to open read-only file for writing, file's sharing mode does not allow specified operations, or given path is directory."; break; case EEXIST: err = "_O_CREAT and _O_EXCL flags specified, but filename already exists."; break; case EINVAL: err = "Invalid oflag or pmode argument."; break; case EMFILE: err = "No more file descriptors available (too many open files)."; break; case ENOENT: err = "File or path not found."; break; } err += " File: |" + filename + "|"; //I don't think this is needed when we get an error opening a file //dx_fileclose(iott.io_fhandle); throw new VoiceException(err); } var state = ATDX_STATE(devh); Logger.Debug("About to play: {0} state: {1}", filename, state); /* Now play the file */ if (dx_playiottdata(devh, ref iott, ref tpt[0], ref xpb, EV_ASYNC) == -1) { Logger.Error("Tried to play: {0} state: {1}", filename, state); var err = ATDV_ERRMSGP(devh); dx_fileclose(iott.io_fhandle); throw new VoiceException(err); } var handler = 0; while (true) { if (sr_waitevtEx(ref devh, 1, -1, ref handler) == -1) { var err = ATDV_ERRMSGP(devh); dx_fileclose(iott.io_fhandle); throw new VoiceException(err); } // make sure the file is closed if (dx_fileclose(iott.io_fhandle) == -1) { var err = ATDV_ERRMSGP(devh); throw new VoiceException(err); } var type = sr_getevttype((uint)handler); if (type == TDX_PLAY) { var reason = ATDX_TERMMSK(devh); if ((reason & TM_ERROR) == TM_ERROR) { throw new VoiceException("TM_ERROR"); } if ((reason & TM_USRSTOP) == TM_USRSTOP) { throw new StopException(); } if ((reason & TM_LCOFF) == TM_LCOFF) { throw new HangupException(); } if ((reason & TM_MAXTIME) == TM_MAXTIME) { Logger.Debug("TM_MAXTIME"); } if ((reason & TM_BARGEIN) == TM_BARGEIN) { Logger.Debug("TM_BARGEIN"); } // if ((reason & TM_DIGIT) == TM_DIGIT) Logger.Debug("TM_DIGIT"); // if ((reason & TM_EOD) == TM_EOD) Logger.Debug("TM_EOD"); // This is how I know they listend to full message if ((reason & TM_IDDTIME) == TM_IDDTIME) { Logger.Debug("TM_IDDTIME"); } if ((reason & TM_MAXDATA) == TM_MAXDATA) { Logger.Debug("TM_MAXDATA"); } // if ((reason & TM_MAXDTMF) == TM_MAXDTMF) Logger.Debug("TM_MAXDTMF"); if ((reason & TM_MAXNOSIL) == TM_MAXNOSIL) { Logger.Debug("TM_MTAXNOSIL"); } if ((reason & TM_MAXSIL) == TM_MAXSIL) { Logger.Debug("TM_MAXSIL"); } // if ((reason & TM_NORMTERM) == TM_NORMTERM) Logger.Debug("TM_NORMTERM"); if ((reason & TM_PATTERN) == TM_PATTERN) { Logger.Debug("TM_PATTERN"); } if ((reason & TM_TONE) == TM_TONE) { Logger.Debug("TM_TONE"); } } else { Logger.Error("got here: {0}", type); } return; } // while }