📄 vxml.h
字号:
BOOL TraverseIf(); BOOL TraverseExit(); BOOL TraverseVar(); BOOL TraverseSubmit(); BOOL TraverseMenu(); BOOL TraverseChoice(const PString & grammarResult); BOOL TraverseProperty(); void SayAs(const PString & className, const PString & text); static PTimeInterval StringToTime(const PString & str); PURL NormaliseResourceName(const PString & src); PXMLElement * FindForm(const PString & id); virtual BOOL TraverseTransfer(); //friend class PVXMLChannel; PSyncPoint waitForEvent; PMutex sessionMutex; PXML xmlFile; PVXMLGrammar * activeGrammar; BOOL listening; // TRUE if waiting for recognition events int timeout; // timeout in msecs for the current recognition PStringToString sessionVars; PStringToString documentVars; PMutex userInputMutex; std::queue<char> userInputQueue; BOOL recording; PFilePath recordFn; BOOL recordDTMFTerm; PTimeInterval recordMaxTime; PTimeInterval recordFinalSilence; PSyncPoint recordSync; BOOL loaded; BOOL finishWhenEmpty; BOOL allowFinish; PURL rootURL; BOOL emptyAction; PThread * vxmlThread; BOOL threadRunning; BOOL forceEnd; PString mediaFormat; PVXMLChannel * vxmlChannel; PTextToSpeech * textToSpeech; BOOL autoDeleteTextToSpeech; PXMLElement * currentForm; PXMLElement * currentField; PXMLObject * currentNode; private: void ExecuteDialog(); PString callingCallToken; PSyncPoint transferSync; PSyncPoint answerSync; PString grammarResult; PString eventName; PINDEX defaultDTMF;};//////////////////////////////////////////////////////////////////class PVXMLRecordable : public PObject{ PCLASSINFO(PVXMLRecordable, PObject); public: PVXMLRecordable() { consecutiveSilence = 0; finalSilence = 3000; maxDuration = 30000; } virtual BOOL Open(const PString & _arg) = 0; virtual void Record(PVXMLChannel & incomingChannel) = 0; virtual void OnStart() { } virtual BOOL OnFrame(BOOL /*isSilence*/) { return FALSE; } virtual void OnStop() { } void SetFinalSilence(unsigned v) { finalSilence = v; } unsigned GetFinalSilence() { return finalSilence; } void SetMaxDuration(unsigned v) { maxDuration = v; } unsigned GetMaxDuration() { return maxDuration; } protected: PTime silenceStart; PTime recordStart; unsigned finalSilence; unsigned maxDuration; unsigned consecutiveSilence;};//////////////////////////////////////////////////////////////////class PVXMLPlayable : public PObject{ PCLASSINFO(PVXMLPlayable, PObject); public: PVXMLPlayable() { repeat = 1; delay = 0; sampleFrequency = 8000; autoDelete = FALSE; delayDone = FALSE; } virtual BOOL Open(PVXMLChannel & /*chan*/, PINDEX _delay, PINDEX _repeat, BOOL _autoDelete) { delay = _delay; repeat = _repeat; autoDelete = _autoDelete; return TRUE; } virtual BOOL Open(PVXMLChannel & chan, const PString & _arg, PINDEX _delay, PINDEX _repeat, BOOL v) { arg = _arg; return Open(chan, _delay, _repeat, v); } virtual void Play(PVXMLChannel & outgoingChannel) = 0; virtual void OnRepeat(PVXMLChannel & /*outgoingChannel*/) { } virtual void OnStart() { } virtual void OnStop() { } virtual void SetRepeat(PINDEX v) { repeat = v; } virtual PINDEX GetRepeat() const { return repeat; } virtual PINDEX GetDelay() const { return delay; } void SetFormat(const PString & _fmt) { format = _fmt; } void SetSampleFrequency(unsigned _rate) { sampleFrequency = _rate; } virtual BOOL ReadFrame(PVXMLChannel & channel, void * buf, PINDEX len); virtual BOOL Rewind(PChannel *) { return FALSE; } friend class PVXMLChannel; protected: PString arg; PINDEX repeat; PINDEX delay; PString format; unsigned sampleFrequency; BOOL autoDelete; BOOL delayDone; // very tacky flag used to indicate when the post-play delay has been done};//////////////////////////////////////////////////////////////////class PVXMLPlayableURL : public PVXMLPlayable{ PCLASSINFO(PVXMLPlayableURL, PVXMLPlayable); public: BOOL Open(PVXMLChannel & chan, const PString & _url, PINDEX _delay, PINDEX _repeat, BOOL v); void Play(PVXMLChannel & outgoingChannel); protected: PURL url;};//////////////////////////////////////////////////////////////////class PVXMLPlayableData : public PVXMLPlayable{ PCLASSINFO(PVXMLPlayableData, PVXMLPlayable); public: BOOL Open(PVXMLChannel & chan, const PString & /*_fn*/, PINDEX _delay, PINDEX _repeat, BOOL v); void SetData(const PBYTEArray & _data); void Play(PVXMLChannel & outgoingChannel); BOOL Rewind(PChannel * chan); protected: PBYTEArray data;};//////////////////////////////////////////////////////////////////class PVXMLPlayableCommand : public PVXMLPlayable{ PCLASSINFO(PVXMLPlayableCommand, PVXMLPlayable); public: PVXMLPlayableCommand(); void Play(PVXMLChannel & outgoingChannel); void OnStop(); protected: PPipeChannel * pipeCmd;};//////////////////////////////////////////////////////////////////class PVXMLPlayableFilename : public PVXMLPlayable{ PCLASSINFO(PVXMLPlayableFilename, PVXMLPlayable); public: BOOL Open(PVXMLChannel & chan, const PString & _fn, PINDEX _delay, PINDEX _repeat, BOOL _autoDelete); void Play(PVXMLChannel & outgoingChannel); void OnStop(); virtual BOOL Rewind(PChannel * chan); protected: PFilePath fn;};//////////////////////////////////////////////////////////////////class PVXMLPlayableFilenameList : public PVXMLPlayable{ PCLASSINFO(PVXMLPlayableFilenameList, PVXMLPlayable); public: BOOL Open(PVXMLChannel & chan, const PStringArray & _filenames, PINDEX _delay, PINDEX _repeat, BOOL _autoDelete); void Play(PVXMLChannel & outgoingChannel) { OnRepeat(outgoingChannel); } void OnRepeat(PVXMLChannel & outgoingChannel); void OnStop(); protected: PINDEX currentIndex; PStringArray filenames;};//////////////////////////////////////////////////////////////////class PVXMLRecordableFilename : public PVXMLRecordable{ PCLASSINFO(PVXMLRecordableFilename, PVXMLRecordable); public: BOOL Open(const PString & _arg); void Record(PVXMLChannel & incomingChannel); BOOL OnFrame(BOOL isSilence); protected: PFilePath fn;};//////////////////////////////////////////////////////////////////PQUEUE(PVXMLQueue, PVXMLPlayable);//////////////////////////////////////////////////////////////////class PVXMLChannel : public PDelayChannel{ PCLASSINFO(PVXMLChannel, PDelayChannel); public: PVXMLChannel(unsigned frameDelay, PINDEX frameSize); ~PVXMLChannel(); virtual BOOL Open(PVXMLChannelInterface * _vxml); // overrides from PIndirectChannel virtual BOOL IsOpen() const; virtual BOOL Close(); virtual BOOL Read(void * buffer, PINDEX amount); virtual BOOL Write(const void * buf, PINDEX len); // new functions virtual PWAVFile * CreateWAVFile(const PFilePath & fn, BOOL recording = FALSE); const PString & GetMediaFormat() const { return mediaFormat; } BOOL IsMediaPCM() const { return mediaFormat == "PCM-16"; } virtual PString AdjustWavFilename(const PString & fn); // Incoming channel functions virtual BOOL WriteFrame(const void * buf, PINDEX len) = 0; virtual BOOL IsSilenceFrame(const void * buf, PINDEX len) const = 0; virtual BOOL QueueRecordable(PVXMLRecordable * newItem); BOOL StartRecording(const PFilePath & fn, unsigned finalSilence = 3000, unsigned maxDuration = 30000); BOOL EndRecording(); BOOL IsRecording() const { return recording; } // Outgoing channel functions virtual BOOL ReadFrame(void * buffer, PINDEX amount) = 0; virtual PINDEX CreateSilenceFrame(void * buffer, PINDEX amount) = 0; virtual void GetBeepData(PBYTEArray &, unsigned) { } virtual BOOL QueueResource(const PURL & url, PINDEX repeat= 1, PINDEX delay = 0); virtual BOOL QueuePlayable(const PString & type, const PString & str, PINDEX repeat = 1, PINDEX delay = 0, BOOL autoDelete = FALSE); virtual BOOL QueuePlayable(PVXMLPlayable * newItem); virtual BOOL QueueData(const PBYTEArray & data, PINDEX repeat = 1, PINDEX delay = 0); virtual BOOL QueueFile(const PString & fn, PINDEX repeat = 1, PINDEX delay = 0, BOOL autoDelete = FALSE) { return QueuePlayable("File", fn, repeat, delay, autoDelete); } virtual BOOL QueueCommand(const PString & cmd, PINDEX repeat = 1, PINDEX delay = 0) { return QueuePlayable("Command", cmd, repeat, delay, TRUE); } virtual void FlushQueue(); virtual BOOL IsPlaying() const { return (playQueue.GetSize() > 0) || playing ; } void SetPause(BOOL _pause) { paused = _pause; } void SetName(const PString & name) { channelName = name; } unsigned GetSampleFrequency() const { return sampleFrequency; } protected: PVXMLChannelInterface * vxmlInterface; unsigned sampleFrequency; PString mediaFormat; PString wavFilePrefix; PMutex channelWriteMutex; PMutex channelReadMutex; BOOL closed; // Incoming audio variables BOOL recording; PVXMLRecordable * recordable; unsigned finalSilence; unsigned silenceRun; // Outgoing audio variables BOOL playing; PMutex queueMutex; PVXMLQueue playQueue; PVXMLPlayable * currentPlayItem; BOOL paused; int silentCount; int totalData; PTimer delayTimer; // "channelname" (which is the name of the <record> tag) so // results can be saved in vxml session variable PString channelName;};//////////////////////////////////////////////////////////////////class PVXMLTransferOptions : public PObject{ PCLASSINFO(PVXMLTransferOptions, PObject); public: PVXMLTransferOptions() { } void SetCallingToken(const PString & calling) { callingToken = calling; } PString GetCallingToken() const { return callingToken; } void SetCalledToken(const PString & called) { calledToken = called; } PString GetCalledToken( ) const { return calledToken; } void SetSourceDNR(const PString & src) { source = src; } PString GetSourceDNR() const { return source; } void SetDestinationDNR(const PString & dest ) { destination = dest; } PString GetDestinationDNR() const { return destination; } void SetTimeout(unsigned int time) { timeout = time; } unsigned int GetTimeout() const { return timeout; } void SetBridge(BOOL brdg) { bridge = brdg; } BOOL GetBridge() const { return bridge; } private: PString callingToken; PString calledToken; PString destination; PString source; unsigned int timeout; BOOL bridge;};class PVXMLTransferResult : public PString{ PCLASSINFO(PVXMLTransferResult, PString); public: PVXMLTransferResult() { } PVXMLTransferResult(char * cstr) : PString( cstr ) { } PVXMLTransferResult(const PString & str ) : PString(str) {} void SetName(const PString & n) { name = n; } PString GetName() const { return name; } private: PString name;};#endif// End of file ////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -