⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adsapiph.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
(***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (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 TurboPower Async Professional
 *
 * The Initial Developer of the Original Code is
 * TurboPower Software
 *
 * Portions created by the Initial Developer are Copyright (C) 1991-2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** *)

{*********************************************************}
{*                   ADSAPIPH.PAS 4.06                   *}
{*********************************************************}
{* TApdSAPIPhone component                               *}
{*********************************************************}

{
  The TApdSapiPhone component descends directly from the TApdTapiDevice,
  so it has similar characteristics. The differences are in the phone prompts,
  and the redirection of the audio streams to/from a TApdSapiEngine.
}

{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}

unit AdSapiPh;

interface

uses
  Windows,
  Messages,
  Classes,
  SysUtils,
  MMSystem,
  INIFiles,
  OoMisc,
  AdSapiEn,
  AdTUtil,
  AdTapi,
  AdSapiGr,
  AdISapi,
  {$IFDEF Delphi6}
  DateUtils,
  Variants,
  {$ENDIF}
  ActiveX,
  ComObj,
  Dialogs;

const
  ApdSapiAskOperator = -3;
  ApdSapiAskHangUp = -4;
  ApdSapiAskBack = -5;
  ApdSapiAskWhere = -10;
  ApdSapiAskHelp = -11;
  ApdSapiAskRepeat = 12;
  ApdSapiAskSpeakFaster = 13;
  ApdSapiAskSpeakSlower = -14;
  ApdSapiAbort = -98;
  ApdSapiTimeout = -99;

  ApdSapiSpeedChange = 25;

  ApdSapiConnect    = 1;
  ApdSapiDisConnect = 2;

  { Replies from the Ask... controls }

  { Replies that are normally not handled by the control }
  ApdTCR_ABORT          = -1;
  ApdTCR_NORESPONSE     = -2;
  ApdTCR_ASKOPERATOR    = -3;
  ApdTCR_ASKHANGUP      = -4;
  ApdTCR_ASKBACK        = -5;
  { Replies that are normally handled by the control }
  ApdTCR_ASKWHERE       = -10;
  ApdTCR_ASKHELP        = -11;
  ApdTCR_ASKREPEAT      = -12;
  ApdTCR_ASKSPEAKFASTER = -13;
  ApdTCR_ASKSPEAKSLOWER = -14;

type


  TApdSapiPhoneSettings = set of (psVerify, psCanGoBack,
                                  psDisableSpeedChange, psEnableOperator,
                                  psEnableAskHangup);
  TApdSapiPhoneReply = (prOk, prAbort, prNoResponse, prOperator, prHangUp,
                        prBack, prWhere, prHelp, prRepeat, prSpeakFaster,
                        prSpeakSlower, prCheck, prError, prUnknown);
  TApdPhraseType = (ptHelp, ptBack, ptOperator, ptHangup, ptRepeat,
                    ptWhere, ptSpeakFaster, ptSpeakSlower, ptUnknown,
                    ptNone, ptCustom, ptAbort, ptTimeout);

  TGrammarStringHandler = (gshIgnore, gshInsert, gshAutoReplace);

  TApdSapiPhoneEvent = procedure (Sender : TObject) of object;
  TApdOnAskForStringFinish = procedure (Sender : TObject;
                                        Reply : TApdSapiPhoneReply;
                                        Data : string;
                                        SpokenData : string) of object;
  TApdOnAskForDateTimeFinish = procedure (Sender : TObject;
                                          Reply : TApdSapiPhoneReply;
                                          Data : TDateTime;
                                          SpokenData : string) of object;
  TApdOnAskForIntegerFinish = procedure (Sender : TObject;
                                         Reply : TApdSapiPhoneReply;
                                         Data : Integer;
                                         SpokenData : string) of object;
  TApdOnAskForBooleanFinish = procedure (Sender : TObject;
                                         Reply : TApdSapiPhoneReply;
                                         Data : Boolean;
                                         SpokenData : string) of object;

  { Internal event to parse custom responses spoken by the user }
  TApdCustomDataHandler = procedure (LastReply : TApdPhraseType;
                                     LastRule : Integer;
                                     LastPhrase : string) of object;
  { Internal event to trigger the OnAskFor...Finish event }
  TApdAskForEventTrigger = procedure (Reply : TApdSapiPhoneReply;
                                      Data : Pointer;
                                      SpokenData : string) of object;

  {$IFNDEF Delphi6}
  PDateTime = ^TDateTime;
  PBoolean = ^Boolean;
  {$ENDIF}

  ESapiPhoneError = class (EApdSapiEngineException);

  TApdSapiGrammarList = class (TStringList)
    private
    protected
    public
      procedure ReadSectionValues (Section : string; List : TStringList);
      function SectionExists (Section : string) : Boolean;
    published
  end;

  TApdSapiPhonePrompts = class (TPersistent)
    private
      FAskAreaCode    : string;
      FAskLastFour    : string;
      FAskNextThree   : string;
      FCannotGoBack   : string;
      FCannotHangUp   : string;
      FGoingBack      : string;
      FHangingUp      : string;
      FHelp           : string;
      FHelp2          : string;
      FHelpVerify     : string;
      FMain           : string;
      FMain2          : string;
      FMaxSpeed       : string;
      FMinSpeed       : string;
      FOperator       : string;
      FNoOperator     : string;
      FNoSpeedChange  : string;
      FSpeakingFaster : string;
      FSpeakingSlower : string;
      FTooFewDigits   : string;
      FTooManyDigits  : string;
      FUnrecognized   : string;
      FVerifyPost     : string;
      FVerifyPre      : string;
      FWhere          : string;
      FWhere2         : string;

    protected
      procedure SetAskAreaCode (v : string);
      procedure SetAskLastFour (v : string);
      procedure SetAskNextThree (v : string);
      procedure SetCannotGoBack (v : string);
      procedure SetCannotHangUp (v : string);
      procedure SetGoingBack (v : string);
      procedure SetHangingUp (v : string);
      procedure SetHelp (v : string);
      procedure SetHelp2 (v : string);
      procedure SetHelpVerify (v : string);
      procedure SetMain (v : string);
      procedure SetMain2 (v : string);
      procedure SetMaxSpeed (v : string);
      procedure SetMinSpeed (v : string);
      procedure SetOperator (v : string);
      procedure SetNoOperator (v : string);
      procedure SetNoSpeedChange (v : string);
      procedure SetSpeakingFaster (v : string);
      procedure SetSpeakingSlower (v : string);
      procedure SetTooFewDigits (v : string);
      procedure SetTooManyDigits (v : string);
      procedure SetUnrecognized (v : string);
      procedure SetVerifyPost (v : string);
      procedure SetVerifyPre (v : string);
      procedure SetWhere (v : string);
      procedure SetWhere2 (v : string);

    public
      constructor Create; 

      function GenerateGrammar (NewPrompt1 : string; NewPrompt2 : string;
                                NewHelp1 : string; NewHelp2 : string;
                                NewWhere1 : string;
                                NewWhere2 : string) : string;
      function GenerateExtensionGrammar (NewTooFewDigits : string;
                                         NewTooManyDigits : string) : string;
      function GeneratePhoneNumberGrammar (NewAskAreaCode : string;
                                           NewAskNextThree : string;
                                           NewAskLastFour : string) : string;

    published
      property AskAreaCode : string read FAskAreaCode write SetAskAreaCode;
      property AskLastFour : string read FAskLastFour write SetAskLastFour;
      property AskNextThree : string read FAskNextThree write SetAskNextThree;
      property CannotGoBack : string read FCannotGoBack write SetCannotGoBack;
      property CannotHangUp : string read FCannotHangUp write SetCannotHangUp;
      property HangingUp : string read FHangingUp write SetHangingUp;
      property Help : string read FHelp write SetHelp;
      property Help2 : string read FHelp2 write SetHelp2;
      property HelpVerify : string read FHelPVerify write SetHelpVerify;
      property GoingBack : string read FGoingBack write SetGoingBack;
      property Main : string read FMain write SetMain;
      property Main2 : string read FMain2 write SetMain2;
      property MaxSpeed : string read FMaxSpeed write SetMaxSpeed;
      property MinSpeed : string read FMinSpeed write SetMinSpeed;
      property Operator : string read FOperator write SetOperator;
      property NoOperator : string read FNoOperator write SetNoOperator;
      property NoSpeedChange : string
               read FNoSpeedChange write SetNoSpeedChange;
      property SpeakingFaster : string
               read FSpeakingFaster write SetSpeakingFaster;
      property SpeakingSlower : string
               read FSpeakingSlower write SetSpeakingSlower;
      property TooFewDigits : string read FTooFewDigits write SetTooFewDigits;
      property TooManyDigits : string
               read FTooManyDigits write SetTooManyDigits;
      property Unrecognized : string read FUnrecognized write SetUnRecognized;
      property VerifyPost : string read FVerifyPost write SetVerifyPost;
      property VerifyPre : string read FVerifyPre write SetVerifyPre;
      property Where : string read FWhere write SetWhere;
      property Where2 : string read FWhere2 write SetWhere2;
  end;

  { TApdSapiAskForInfo handles the actual work of asking the user for a
    response.  This handles getting help, repeating prompts and related
    items }

  TApdSapiAskForInfo = class (TObject)
    private
      FReplyHandle   : THandle;
      FPrompts       : TApdSapiPhonePrompts;
      FSapiEngine    : TApdCustomSapiEngine;
      FAskForGrammar : TStringList;
      FMainGrammar   : TStringList;
      FOptions       : TApdSapiPhoneSettings;
      FStringHandler : TGrammarStringHandler;

    protected
      function DeterminePhraseTypeEx (Phrase : string;
                                      var Rule : string) : TApdPhraseType;
      function IsAnglePhrase (Phrase : string) : Boolean;
      function IsParenPhrase (Phrase : string) : Boolean;
      function IsQuoted (Phrase : string) : Boolean;
      function KillQuotes (Phrase : string) : string;
      function GetValue (Value : string) : string;
      function GetKey (Value : string) : string;
      function AnalyzeRule (Tokens : TStringList; CurrentRule : string;
                            INIFile : TApdSapiGrammarList;
                            CurrentSection : TStringList;
                            var CurrentWord : Integer;
                            var MatchingKey : string
                            ) : Boolean;
      function RecurseRules (Tokens : TStringList;
                             INIFile : TApdSapiGrammarList;
                             CurrentSection : string;
                             var CurrentWord : Integer;
                             var MatchingKey : string
                             ) : Boolean;
      function LocateRule (Tokens : TStringList) : string;
      procedure InitializeMainGrammar;
      procedure SapiPhraseFinishHook (Sender : TObject; Phrase : string;
                                      Results : Integer); virtual;
      procedure SetAskForGrammar (v : TStringList);
      procedure SetMainGrammar (v : TStringList);
      procedure SetOptions (v : TApdSapiPhoneSettings);
      procedure SetReplyHandle (v : THandle);

    public
      constructor Create;
      destructor Destroy; override;

      procedure AskFor;
      function DeterminePhraseType (Phrase : string) : TApdPhraseType;
      function FindGrammarRule (var Phrase : string) : string;

    published
      property AskForGrammar : TStringList
               read FAskForGrammar write SetAskForGrammar;
      property MainGrammar : TStringList
               read FMainGrammar write SetMainGrammar;
      property Options : TApdSapiPhoneSettings read FOptions write SetOptions;
      property Prompts : TApdSapiPhonePrompts read FPrompts write FPrompts;
      property ReplyHandle : THandle read FReplyHandle write SetReplyHandle;
      property SapiEngine : TApdCustomSapiEngine
               read FSapiEngine write FSapiEngine;
  end;

  TApdCustomSapiPhone = class (TApdCustomTapiDevice)
    private
      FSapiEngine                : TApdCustomSapiEngine;
      IAMM                       : IAudioMultiMediaDevice;
      IAT                        : IAudioTel;

      FNumDigits                 : Integer;
      FNoAnswerMax               : Integer;
      FNoAnswerTime              : Integer;
      FOptions                   : TApdSapiPhoneSettings;
      FInAskFor                  : Boolean;
      FSpellingEchoBack          : Boolean;

      FPrompts                   : TApdSapiPhonePrompts;
      FInfo                      : TApdSapiAskForInfo;

      FExtension                 : string;
      FDigitCount                : Integer;
      FSpelledWord               : string;
      FList                      : TStringList;

      FCustomDataHandler         : TApdCustomDataHandler;
      FEventTrigger              : TApdAskForEventTrigger;

      FOnAskForDateFinish        : TApdOnAskForDateTimeFinish;
      FOnAskForExtensionFinish   : TApdOnAskForStringFinish;
      FOnAskForListFinish        : TApdOnAskForIntegerFinish;
      FOnAskForPhoneNumberFinish : TApdOnAskForStringFinish;
      FOnAskForSpellingFinish    : TApdOnAskForStringFinish;
      FOnAskForTimeFinish        : TApdOnAskForDateTimeFinish;
      FOnAskForYesNoFinish       : TApdOnAskForBooleanFinish;
      FOnTapiDisconnect          : TNotifyEvent;

    protected
      procedure AskForDateDataHandler (LastReply : TApdPhraseType;
                                       LastRule : Integer;
                                       LastPhrase : string);
      procedure AskForExtensionDataHandler (LastReply : TApdPhraseType;
                                       LastRule : Integer;
                                       LastPhrase : string);
      procedure AskForListDataHandler (LastReply : TApdPhraseType;
                                       LastRule : Integer;
                                       LastPhrase : string);
      procedure AskForPhoneNumberDataHandler (LastReply : TApdPhraseType;
                                       LastRule : Integer;
                                       LastPhrase : string);
      procedure AskForSpellingDataHandler (LastReply : TApdPhraseType;
                                       LastRule : Integer;
                                       LastPhrase : string);
      procedure AskForTimeDataHandler (LastReply : TApdPhraseType;
                                       LastRule : Integer;
                                       LastPhrase : string);
      procedure AskForYesNoDataHandler (LastReply : TApdPhraseType;
                                       LastRule : Integer;
                                       LastPhrase : string);

      procedure AskForDateTrigger (Reply : TApdSapiPhoneReply;
                                   Data : Pointer;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -