/usr/include/ptclib/vxml.h is in libpt2.4.5-dev 2.4.5-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | /*
* vxml.h
*
* VXML engine for pwlib library
*
* Copyright (C) 2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 20385 $
* $Author: rjongbloed $
* $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
*/
#ifndef _VXML_H
#define _VXML_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptclib/pxml.h>
#if P_VXML
#include <ptlib/pipechan.h>
#include <ptclib/delaychan.h>
#include <ptclib/pwavfile.h>
#include <ptclib/ptts.h>
#include <ptclib/url.h>
#include <queue>
class PVXMLSession;
class PVXMLDialog;
class PVXMLSession;
// these are the same strings as the Opal equivalents, but as this is PWLib, we can't use Opal contants
#define VXML_PCM16 "PCM-16"
#define VXML_G7231 "G.723.1"
#define VXML_G729 "G.729"
#define PVXML_HAS_FACTORY 1
class PVXMLGrammar : public PObject
{
PCLASSINFO(PVXMLGrammar, PObject);
public:
PVXMLGrammar(PXMLElement * field);
virtual PBoolean OnUserInput(const char /*ch*/) { return PTrue; }
virtual void Stop() { }
PString GetValue() const { return value; }
PXMLElement * GetField() { return field; }
enum GrammarState {
FILLED, ///< got something that matched the grammar
NOINPUT, ///< timeout or still waiting to match
NOMATCH, ///< recognized something but didn't match the grammar
HELP }; ///< help keyword
GrammarState GetState() const { return state; }
protected:
PXMLElement * field;
PString value;
GrammarState state;
};
//////////////////////////////////////////////////////////////////
class PVXMLMenuGrammar : public PVXMLGrammar
{
PCLASSINFO(PVXMLMenuGrammar, PVXMLGrammar);
public:
PVXMLMenuGrammar(PXMLElement * field);
};
//////////////////////////////////////////////////////////////////
class PVXMLDigitsGrammar : public PVXMLGrammar
{
PCLASSINFO(PVXMLDigitsGrammar, PVXMLGrammar);
public:
PVXMLDigitsGrammar(PXMLElement * field, PINDEX minDigits, PINDEX maxDigits, PString terminators);
PBoolean OnUserInput(const char ch);
virtual void Stop();
protected:
PINDEX minDigits;
PINDEX maxDigits;
PString terminators;
};
//////////////////////////////////////////////////////////////////
class PVXMLCache : public PMutex
{
public:
PVXMLCache(const PDirectory & _directory);
PFilePath CreateFilename(const PString & prefix, const PString & key, const PString & fileType);
void Put(const PString & prefix,
const PString & key,
const PString & fileType,
const PString & contentType,
const PFilePath & fn,
PFilePath & dataFn);
PBoolean Get(const PString & prefix,
const PString & key,
const PString & fileType,
PString & contentType,
PFilePath & fn);
PFilePath GetCacheDir() const
{ return directory; }
PFilePath GetRandomFilename(const PString & prefix, const PString & fileType);
static PVXMLCache & GetResourceCache();
protected:
PDirectory directory;
};
//////////////////////////////////////////////////////////////////
class PVXMLChannel;
class PVXMLChannelInterface {
public:
virtual ~PVXMLChannelInterface() { }
virtual PWAVFile * CreateWAVFile(const PFilePath & fn, PFile::OpenMode mode, int opts, unsigned fmt) = 0;
virtual void RecordEnd() = 0;
virtual void OnEndRecording(const PString & channelName) = 0;
virtual void Trigger() = 0;
};
//////////////////////////////////////////////////////////////////
class PVXMLSession : public PIndirectChannel, public PVXMLChannelInterface
{
PCLASSINFO(PVXMLSession, PIndirectChannel);
public:
PVXMLSession(PTextToSpeech * tts = NULL, PBoolean autoDelete = PFalse);
virtual ~PVXMLSession();
// new functions
PTextToSpeech * SetTextToSpeech(PTextToSpeech * _tts, PBoolean autoDelete = PFalse);
PTextToSpeech * SetTextToSpeech(const PString & ttsName);
PTextToSpeech * GetTextToSpeech() { return textToSpeech; }
virtual PBoolean Load(const PString & source);
virtual PBoolean LoadFile(const PFilePath & file);
virtual PBoolean LoadURL(const PURL & url);
virtual PBoolean LoadVXML(const PString & xml);
virtual PBoolean IsLoaded() const { return loaded; }
virtual PBoolean Open(const PString & mediaFormat);
virtual PBoolean Close();
PBoolean Execute();
PVXMLChannel * GetAndLockVXMLChannel()
{
sessionMutex.Wait();
if (vxmlChannel != NULL)
return vxmlChannel;
sessionMutex.Signal();
return NULL;
}
void UnLockVXMLChannel() { sessionMutex.Signal(); }
PMutex & GetSessionMutex() { return sessionMutex; }
PBoolean LoadGrammar(PVXMLGrammar * grammar);
virtual PBoolean PlayText(const PString & text, PTextToSpeech::TextType type = PTextToSpeech::Default, PINDEX repeat = 1, PINDEX delay = 0);
PBoolean ConvertTextToFilenameList(const PString & _text, PTextToSpeech::TextType type, PStringArray & list, PBoolean useCacheing);
virtual PBoolean PlayFile(const PString & fn, PINDEX repeat = 1, PINDEX delay = 0, PBoolean autoDelete = PFalse);
virtual PBoolean PlayData(const PBYTEArray & data, PINDEX repeat = 1, PINDEX delay = 0);
virtual PBoolean PlayCommand(const PString & data, PINDEX repeat = 1, PINDEX delay = 0);
virtual PBoolean PlayResource(const PURL & url, PINDEX repeat = 1, PINDEX delay = 0);
virtual PBoolean PlayTone(const PString & toneSpec, PINDEX repeat = 1, PINDEX delay = 0);
//virtual PBoolean PlayMedia(const PURL & url, PINDEX repeat = 1, PINDEX delay = 0);
virtual PBoolean PlaySilence(PINDEX msecs = 0);
virtual PBoolean PlaySilence(const PTimeInterval & timeout);
virtual PBoolean PlayStop();
virtual void SetPause(PBoolean pause);
virtual void GetBeepData(PBYTEArray & data, unsigned ms);
virtual PBoolean StartRecording(const PFilePath & fn, PBoolean recordDTMFTerm, const PTimeInterval & recordMaxTime, const PTimeInterval & recordFinalSilence);
virtual PBoolean EndRecording();
virtual PBoolean IsPlaying() const;
virtual PBoolean IsRecording() const;
virtual PBoolean OnUserInput(const PString & str);
PString GetXMLError() const;
virtual void OnEndSession() { }
virtual PString GetVar(const PString & str) const;
virtual void SetVar(const PString & ostr, const PString & val);
virtual PString EvaluateExpr(const PString & oexpr);
virtual PBoolean RetreiveResource(const PURL & url, PString & contentType, PFilePath & fn, PBoolean useCache = PTrue);
PDECLARE_NOTIFIER(PThread, PVXMLSession, VXMLExecute);
void SetCallingToken( PString& token ) { callingCallToken = token; }
PXMLElement * FindHandler(const PString & event);
// overrides from VXMLChannelInterface
PWAVFile * CreateWAVFile(const PFilePath & fn, PFile::OpenMode mode, int opts, unsigned fmt);
void OnEndRecording(const PString & channelName);
void RecordEnd();
void Trigger();
PStringToString & GetSessionVars() { return sessionVars; }
protected:
void Initialise();
void AllowClearCall();
void ProcessUserInput();
void ProcessNode();
void ProcessGrammar();
PBoolean TraverseAudio();
PBoolean TraverseGoto();
PBoolean TraverseGrammar();
PBoolean TraverseRecord();
PBoolean TraverseIf();
PBoolean TraverseExit();
PBoolean TraverseVar();
PBoolean TraverseSubmit();
PBoolean TraverseMenu();
PBoolean TraverseChoice(const PString & grammarResult);
PBoolean TraverseProperty();
void SayAs(const PString & className, const PString & text);
void SayAs(const PString & className, const PString & text, const PString & voice);
static PTimeInterval StringToTime(const PString & str);
PURL NormaliseResourceName(const PString & src);
PXMLElement * FindForm(const PString & id);
//friend class PVXMLChannel;
PSyncPoint waitForEvent;
PMutex sessionMutex;
PXML xmlFile;
PVXMLGrammar * activeGrammar;
PBoolean listening; // PTrue if waiting for recognition events
int timeout; // timeout in msecs for the current recognition
PStringToString sessionVars;
PStringToString documentVars;
PMutex userInputMutex;
std::queue<char> userInputQueue;
PBoolean recording;
PFilePath recordFn;
PBoolean recordDTMFTerm;
PTimeInterval recordMaxTime;
PTimeInterval recordFinalSilence;
PSyncPoint recordSync;
PBoolean loaded;
PURL rootURL;
PBoolean emptyAction;
PThread * vxmlThread;
PBoolean threadRunning;
PBoolean forceEnd;
PString mediaFormat;
PVXMLChannel * vxmlChannel;
PTextToSpeech * textToSpeech;
PBoolean autoDeleteTextToSpeech;
PXMLElement * currentForm;
PXMLElement * currentField;
PXMLObject * currentNode;
private:
void ExecuteDialog();
PString callingCallToken;
PSyncPoint answerSync;
PString grammarResult;
PString eventName;
PINDEX defaultDTMF;
};
//////////////////////////////////////////////////////////////////
class PVXMLRecordable : public PObject
{
PCLASSINFO(PVXMLRecordable, PObject);
public:
PVXMLRecordable()
{ consecutiveSilence = 0; finalSilence = 3000; maxDuration = 30000; }
virtual PBoolean Open(const PString & _arg) = 0;
virtual void Record(PVXMLChannel & incomingChannel) = 0;
virtual void OnStart() { }
virtual PBoolean OnFrame(PBoolean /*isSilence*/) { return PFalse; }
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 = PFalse; delayDone = PFalse; }
virtual PBoolean Open(PVXMLChannel & /*chan*/, PINDEX _delay, PINDEX _repeat, PBoolean _autoDelete);
virtual PBoolean Open(PVXMLChannel & chan, const PString & _arg, PINDEX _delay, PINDEX _repeat, PBoolean 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 PBoolean ReadFrame(PVXMLChannel & channel, void * buf, PINDEX len);
virtual PBoolean Rewind(PChannel *)
{ return PFalse; }
friend class PVXMLChannel;
protected:
PString arg;
PINDEX repeat;
PINDEX delay;
PString format;
unsigned sampleFrequency;
PBoolean autoDelete;
PBoolean delayDone; // very tacky flag used to indicate when the post-play delay has been done
};
//////////////////////////////////////////////////////////////////
class PVXMLPlayableStop : public PVXMLPlayable
{
PCLASSINFO(PVXMLPlayableStop, PVXMLPlayable);
public:
virtual void Play(PVXMLChannel & outgoingChannel);
virtual PBoolean ReadFrame(PVXMLChannel & channel, void *, PINDEX);
};
//////////////////////////////////////////////////////////////////
class PVXMLPlayableURL : public PVXMLPlayable
{
PCLASSINFO(PVXMLPlayableURL, PVXMLPlayable);
public:
PBoolean Open(PVXMLChannel & chan, const PString & _url, PINDEX _delay, PINDEX _repeat, PBoolean v);
void Play(PVXMLChannel & outgoingChannel);
protected:
PURL url;
};
//////////////////////////////////////////////////////////////////
class PVXMLPlayableData : public PVXMLPlayable
{
PCLASSINFO(PVXMLPlayableData, PVXMLPlayable);
public:
PBoolean Open(PVXMLChannel & chan, const PString & /*_fn*/, PINDEX _delay, PINDEX _repeat, PBoolean v);
void SetData(const PBYTEArray & _data);
void Play(PVXMLChannel & outgoingChannel);
PBoolean Rewind(PChannel * chan);
protected:
PBYTEArray data;
};
//////////////////////////////////////////////////////////////////
#include <ptclib/dtmf.h>
class PVXMLPlayableTone : public PVXMLPlayableData
{
PCLASSINFO(PVXMLPlayableTone, PVXMLPlayableData);
public:
PBoolean Open(PVXMLChannel & chan, const PString & toneSpec, PINDEX _delay, PINDEX _repeat, PBoolean v);
protected:
PTones tones;
};
//////////////////////////////////////////////////////////////////
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:
PBoolean Open(PVXMLChannel & chan, const PString & _fn, PINDEX _delay, PINDEX _repeat, PBoolean _autoDelete);
void Play(PVXMLChannel & outgoingChannel);
void OnStop();
virtual PBoolean Rewind(PChannel * chan);
protected:
PFilePath fn;
};
//////////////////////////////////////////////////////////////////
class PVXMLPlayableFilenameList : public PVXMLPlayable
{
PCLASSINFO(PVXMLPlayableFilenameList, PVXMLPlayable);
public:
PBoolean Open(PVXMLChannel & chan, const PStringArray & _filenames, PINDEX _delay, PINDEX _repeat, PBoolean _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:
PBoolean Open(const PString & _arg);
void Record(PVXMLChannel & incomingChannel);
PBoolean OnFrame(PBoolean isSilence);
protected:
PFilePath fn;
};
//////////////////////////////////////////////////////////////////
PQUEUE(PVXMLQueue, PVXMLPlayable);
//////////////////////////////////////////////////////////////////
class PVXMLChannel : public PDelayChannel
{
PCLASSINFO(PVXMLChannel, PDelayChannel);
public:
PVXMLChannel(unsigned frameDelay, PINDEX frameSize);
~PVXMLChannel();
virtual PBoolean Open(PVXMLChannelInterface * _vxml);
// overrides from PIndirectChannel
virtual PBoolean IsOpen() const;
virtual PBoolean Close();
virtual PBoolean Read(void * buffer, PINDEX amount);
virtual PBoolean Write(const void * buf, PINDEX len);
// new functions
virtual PWAVFile * CreateWAVFile(const PFilePath & fn, PBoolean recording = PFalse);
const PString & GetMediaFormat() const { return mediaFormat; }
PBoolean IsMediaPCM() const { return mediaFormat == "PCM-16"; }
virtual PString AdjustWavFilename(const PString & fn);
// Incoming channel functions
virtual PBoolean WriteFrame(const void * buf, PINDEX len) = 0;
virtual PBoolean IsSilenceFrame(const void * buf, PINDEX len) const = 0;
virtual PBoolean QueueRecordable(PVXMLRecordable * newItem);
PBoolean StartRecording(const PFilePath & fn, unsigned finalSilence = 3000, unsigned maxDuration = 30000);
PBoolean EndRecording();
PBoolean IsRecording() const { return recording; }
// Outgoing channel functions
virtual PBoolean ReadFrame(void * buffer, PINDEX amount) = 0;
virtual PINDEX CreateSilenceFrame(void * buffer, PINDEX amount) = 0;
virtual void GetBeepData(PBYTEArray &, unsigned) { }
virtual PBoolean QueueResource(const PURL & url, PINDEX repeat= 1, PINDEX delay = 0);
virtual PBoolean QueuePlayable(const PString & type, const PString & str, PINDEX repeat = 1, PINDEX delay = 0, PBoolean autoDelete = PFalse);
virtual PBoolean QueuePlayable(PVXMLPlayable * newItem);
virtual PBoolean QueueData(const PBYTEArray & data, PINDEX repeat = 1, PINDEX delay = 0);
virtual PBoolean QueueFile(const PString & fn, PINDEX repeat = 1, PINDEX delay = 0, PBoolean autoDelete = PFalse)
{ return QueuePlayable("File", fn, repeat, delay, autoDelete); }
virtual PBoolean QueueCommand(const PString & cmd, PINDEX repeat = 1, PINDEX delay = 0)
{ return QueuePlayable("Command", cmd, repeat, delay, PTrue); }
virtual void FlushQueue();
virtual PBoolean IsPlaying() const { return (playQueue.GetSize() > 0) || playing ; }
void SetPause(PBoolean _pause) { paused = _pause; }
void SetName(const PString & name) { channelName = name; }
unsigned GetSampleFrequency() const
{ return sampleFrequency; }
void SetSilentCount(int v) { silentCount = v; }
protected:
PVXMLChannelInterface * vxmlInterface;
unsigned sampleFrequency;
PString mediaFormat;
PString wavFilePrefix;
PMutex channelWriteMutex;
PMutex channelReadMutex;
PBoolean closed;
// Incoming audio variables
PBoolean recording;
PVXMLRecordable * recordable;
unsigned finalSilence;
unsigned silenceRun;
// Outgoing audio variables
PBoolean playing;
PMutex queueMutex;
PVXMLQueue playQueue;
PVXMLPlayable * currentPlayItem;
PBoolean 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;
};
//////////////////////////////////////////////////////////////////
#endif // P_VXML
#endif // _VXML_H
// End of file ////////////////////////////////////////////////////////////////
|