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

📄 adsapien.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:

  { Event types }

  TApdOnSapiError =
      procedure (Sender : TObject; Error : LongWord;
                 const Details : string; const Message : string) of object;
  TApdSapiNotifyEvent =
      procedure (Sender : TObject) of object;
  TApdSRInterferenceEvent =
      procedure (Sender : TObject;
                 InterferenceType : TApdSRInterferenceType) of object;
  TApdSRPhraseFinishEvent =
      procedure (Sender : TObject; const Phrase : string) of object;
  TApdSRPhraseHypothesisEvent =
      procedure (Sender : TObject; const Phrase : string) of object;
  TApdSRTrainingRequestedEvent =
      procedure (Sender : TObject; Training : TApdSRTrainingType) of object;
  TApdSRVUMeterEvent =
      procedure (Sender : TObject; Level : Integer) of object;
  TApdSSAttributeChanged =
      procedure (Sender : TObject; Attribute: Integer) of object;

  { Hook methods }

  TApdPhraseFinishMethod =
    procedure (Sender : TObject; Phrase : string; Results : Integer) of object;
  PApdPhraseFinishMethod = ^TApdPhraseFinishMethod;

  TApdRegisteredEventTypes = (etPhraseFinish);
  PApdRegisteredEvent = ^TApdRegisteredEvent;
  TApdRegisteredEvent = record
    CallBack : TApdPhraseFinishMethod;
    EventType : TApdRegisteredEventTypes;
    Active : Boolean;
  end;

  { Exceptions }

  EApdSapiEngineException = class (Exception)
    private
      FErrorCode : Integer;

    public
      constructor Create (const ErrCode : Integer; const Msg : string);
      { Note: ErrCode is before the string to prevent problems in compiling
              with C++ Builder }

    published
      property ErrorCode : Integer read FErrorCode;
  end;

  { TApdSSVoices }
  
  TApdSSVoices = class (TObject)
    private
      FCurrentVoice : Integer;
      FiDirectSS    : TDirectSS;

    protected
      function CheckIndex (x : Integer) : Boolean;
      function GetAge (x : Integer) : TApdTTSAge;
      function GetCount : Integer;
      function GetCurrentVoice : Integer;
      function GetDialect (x : Integer) : string;
      function GetEngineFeatures (x : Integer) : Integer;
      function GetEngineID (x : Integer) : string;
      function GetFeatures (x : Integer) : TApdTTSFeatures;
      function GetGender (x : Integer) : TApdTTSGender;
      function GetInterfaces (x : Integer) : TApdTTSInterfaces;
      function GetLanguageID (x : Integer) : Integer;
      function GetMfgName (x : Integer) : string;
      function GetModeID (x : Integer) : string;
      function GetModeName (x : Integer) : string;
      function GetProductName (x : Integer) : string;
      function GetSpeaker (x : Integer) : string;
      function GetStyle (x : Integer) : string;
      procedure SetCurrentVoice (v : Integer);

    public
      function Find (Criteria : string) : Integer;

      property Age[x : Integer] : TApdTTSAge read GetAge;
      property Dialect[x : Integer] : string read GetDialect;
      property EngineFeatures[x : Integer] : Integer read GetEngineFeatures;
      property EngineID[x : Integer] : string read GetEngineID;
      property Features[x : Integer] : TApdTTSFeatures read GetFeatures;
      property Gender[x : Integer] : TApdTTSGender read GetGender;
      property Interfaces[x : Integer] : TApdTTSInterfaces read GetInterfaces;
      property LanguageID[x : Integer] : Integer read GetLanguageID;
      property MfgName[x : Integer] : string read GetMfgName;
      property ModeID[x : Integer] : string read GetModeID;
      property ModeName[x : Integer] : string read GetModeName; default;
      property ProductName[x : Integer] : string read GetProductName;
      property Speaker[x : Integer] : string read GetSpeaker;
      property Style[x : Integer] : string read GetStyle;

    published
      property Count : Integer read GetCount;
      property CurrentVoice : Integer
               read GetCurrentVoice write SetCurrentVoice;
  end;

  { TApdSREngines }
  
  TApdSREngines = class (TObject)
    private
      FCurrentEngine : Integer;
      FiDirectSR     : TDirectSR;

    protected
      function  CheckIndex (x : Integer) : Boolean;

      function  GetCount : Integer;
      function  GetCurrentEngine : Integer;
      function  GetDialect (x : Integer) : string;
      function  GetEngineFeatures (x : Integer) : Integer;
      function  GetEngineId (x : Integer) : string;
      function  GetFeatures (x : Integer) : TApdSRFeatures;
      function  GetGrammars (x : Integer) : TApdSRGrammars;
      function  GetInterfaces (x : Integer) : TApdSRInterfaces;
      function  GetLanguageID (x : Integer) : Integer;
      function  GetMaxWordsState (x : Integer) : Integer;
      function  GetMaxWordsVocab (x : Integer) : Integer;
      function  GetMfgName (x : Integer) : string;
      function  GetModeID (x : Integer) : string;
      function  GetModeName (x : Integer) : string;
      function  GetProductName (x : Integer) : string;
      function  GetSequencing (x : Integer) : TApdSRSequences;
      procedure SetCurrentEngine (v : Integer);

    public
      property Dialect[x : Integer] : string read GetDialect;
      property EngineFeatures[x : Integer] : Integer read GetEngineFeatures;
      property EngineID[x : Integer] : string read GetEngineID;
      property Features[x : Integer] : TApdSRFeatures read GetFeatures;
      property Grammars[x : Integer] : TApdSRGrammars read GetGrammars;
      property Interfaces[x : Integer] : TApdSRInterfaces read GetInterfaces;
      property LanguageID[x : Integer] : Integer read GetLanguageID;
      property MaxWordsState[x : Integer] : Integer read GetMaxWordsState;
      property MaxWordsVocab[x : Integer] : Integer read GetMaxWordsVocab;
      property MfgName[x : Integer] : string read GetMfgName;
      property ModeID[x : Integer] : string read GetModeID;
      property ModeName[x : Integer] : string read GetModeName; default;
      property ProductName[x : Integer] : string read GetProductName;
      property Sequencing[x : Integer] : TApdSRSequences read GetSequencing;

    published
      property Count : Integer read GetCount;
      property CurrentEngine : Integer
               read GetCurrentEngine write SetCurrentEngine;

  end;

  { TApdCustomSapiEngine }

  TApdCustomSapiEngine = class (TApdBaseComponent) 
    private
      FiDirectSR                : TDirectSR;
      FiDirectSS                : TDirectSS;
      FCharSet                  : TApdCharacterSet;
      FDictation                : Boolean;
      FSpeaking                 : Boolean;
      FListening                : Boolean;
      FSRAmplitude              : Word;
      FSRAutoGain               : Integer;
      FTTSOptions               : TApdTTSOptions;
      FWordList                 : TStringList;
      FSREngines                : TApdSREngines;
      FSSVoices                 : TApdSSVoices;
      FPhraseFinishClients      : TList;
      FHandle                   : HWnd;
      FAutoTrain                : Boolean;
      FDuplex                   : TApdSapiDuplex;
      FWaitMode                 : TApdSapiWaitMode;
      FInitSR                   : Boolean;                               {!!.04}
      FInitSS                   : Boolean;                               {!!.04}

      FOnInterference           : TApdSRInterferenceEvent;
      FOnPhraseFinish           : TApdSRPhraseFinishEvent;
      FOnPhraseHypothesis       : TApdSRPhraseHypothesisEvent;
      FOnSpeakStart             : TApdSapiNotifyEvent;
      FOnSpeakStop              : TApdSapiNotifyEvent;
      FOnSRError                : TApdOnSapiError;
      FOnSRWarning              : TApdOnSapiError;
      FOnSSAttributeChanged     : TApdSSAttributeChanged;
      FOnSSError                : TApdOnSapiError;
      FOnSSWarning              : TApdOnSapiError;
      FOnTrainingRequested      : TApdSRTrainingRequestedEvent;
      FOnVUMeter                : TApdSRVUMeterEvent;

    protected
      function GetSRAmplitude : Word;
      function GetSRAutoGain : Integer;
      procedure InitializeSpeaking (var CSet : Integer;
                                    var Options : Integer);
      procedure Loaded; override;
      procedure SetAutoTrain (v : Boolean);
      procedure SetCharSet (v : TApdCharacterSet);
      procedure SetDictation (v : Boolean);
      procedure SetDuplex (v : TApdSapiDuplex);
      procedure SetInitSR (const v : Boolean);                           {!!.04}
      procedure SetInitSS (const v : Boolean);                           {!!.04}                                  
      procedure SetListening (v : Boolean);
      procedure SetSpeaking (v : Boolean);
      procedure SetSRAutoGain (Value: Integer);
      procedure SetTTSOptions (v : TApdTTSOptions);
      procedure SetWordList (v : TStringList);

      procedure TriggerAudioStart (Sender : TObject; hi : Integer;
                                   lo : Integer);
      procedure TriggerAudioStop (Sender : TObject; hi : Integer;
                                  lo : Integer);
      procedure TriggerInterference (Sender : TObject; beginhi : Integer;
                                     beginlo : Integer; endhi : Integer;
                                     endlo : Integer; type_ : Integer);
      procedure TriggerPhraseFinish (Sender : TObject; flags : Integer;
                                     beginhi : Integer; beginlo : Integer;
                                     endhi : Integer; endlo : Integer;
                                     const Phrase : WideString;
                                     const parsed : WideString;
                                     results : Integer);
      procedure TriggerPhraseFinishClients (Phrase : string; Results : Integer);
      procedure TriggerPhraseHypothesis (Sender : TObject; flags : Integer;
                                         beginhi : Integer; beginlo : Integer;
                                         endhi : Integer; endlo : Integer;
                                         const Phrase : WideString;
                                         results : Integer);
      procedure TriggerSpeakStart (Sender : TObject; beginhi : Integer;
                                   beginlo : Integer);
      procedure TriggerSpeakStop (Sender : TObject; beginhi : Integer;
                                  beginlo : Integer; endhi : Integer;
                                  endlo : Integer);
      procedure TriggerSRError (Sender : TObject; Error : LongWord;
                                const Details : WideString;
                                const Message : WideString);
      procedure TriggerSRWarning (Sender : TObject; Error : LongWord;
                                  const Details : WideString;
                                  const Message : WideString);
      procedure TriggerSSAttribChanged (Sender : TObject; Attribute: Integer);
      procedure TriggerSSError (Sender : TObject; Error : LongWord;
                                const Details : WideString;
                                const Message : WideString);
      procedure TriggerSSWarning (Sender : TObject; Error : LongWord;
                                  const Details : WideString;
                                  const Message : WideString);
      procedure TriggerTrainingRequested (Sender : TObject; train : Integer);
      procedure TriggerVUMeter (Sender : TObject; beginhi : Integer;
                                beginlo : Integer; level : Integer);
      procedure WndProc (var Message : TMessage);

    public
      constructor Create (AOwner : TComponent); override;
      destructor Destroy; override;

      procedure CheckError (ErrorCode : DWORD);
      procedure DeRegisterPhraseFinishHook (
                                 PhraseFinishMethod : TApdPhraseFinishMethod);
      procedure InitializeSapi;                                        {!!.01}
      procedure InitializeSR;                                          {!!.04}
      procedure InitializeSS;                                          {!!.04}
      function IsSapi4Installed : Boolean;
      procedure Listen;
      procedure PauseListening;
      procedure PauseSpeaking;
      procedure RegisterPhraseFinishHook (
                                 PhraseFinishMethod : TApdPhraseFinishMethod);
      procedure ResumeListening;
      procedure ResumeSpeaking;
      procedure ShowAboutDlg (const Caption : string);
      procedure ShowGeneralDlg (const Caption : string);
      procedure ShowLexiconDlg (const Caption : string);
      procedure ShowSRAboutDlg (const Caption : string);
      procedure ShowSRGeneralDlg (const Caption : string);
      procedure ShowSRLexiconDlg (const Caption : string);
      procedure ShowSSAboutDlg (const Caption : string);
      procedure ShowSSGeneralDlg (const Caption : string);
      procedure ShowSSLexiconDlg (const Caption : string);
      procedure ShowTrainGeneralDlg (const Caption : string);
      procedure ShowTrainMicDlg (const Caption : string);
      procedure ShowTranslateDlg (const Caption : string);
      procedure Speak (Text : string);
      procedure SpeakFile (FileName : string);
      procedure SpeakFileToFile (const InFile, OutFile : string);
      procedure SpeakStream (Stream : TStream; FileName : string);
      procedure SpeakToFile (const Text, FileName : string);
      procedure StopListening;
      procedure StopSpeaking;
      procedure WaitUntilDoneSpeaking;

      property DirectSR : TDirectSR read FiDirectSR write FiDirectSR;
      property DirectSS : TDirectSS read FiDirectSS write FiDirectSS;
      property InitSR : Boolean read FInitSR write SetInitSR             {!!.04}
               default True;                                             {!!.04}
      property InitSS : Boolean read FInitSS write SetInitSS             {!!.04}
               default True;                                             {!!.04}
      property Listening : Boolean read FListening write SetListening;
      property Speaking : Boolean read FSpeaking write SetSpeaking;
      property SREngines: TApdSREngines
               read FSREngines write FSREngines;
      property SSVoices : TApdSSVoices
               read FSSVoices write FSSVoices;

    published
      property AutoTrain : Boolean read FAutoTrain write SetAutoTrain
               default False;
      property CharSet : TApdCharacterSet read FCharSet write SetCharSet;
      property Dictation : Boolean read FDictation write SetDictation;
      property Duplex : TApdSapiDuplex
               read FDuplex write SetDuplex default sdHalfDelayed;
      property SRAmplitude : Word read GetSRAmplitude;
      property SRAutoGain : Integer read GetSRAutoGain write SetSRAutoGain;
      property TTSOptions : TApdTTSOptions
               read FTTSOptions write SetTTSOptions;
      property WordList : TStringLIst read FWordList write SetWordList;

      property OnInterference : TApdSRInterferenceEvent
               read FOnInterference write FOnInterference;
      property OnPhraseFinish : TApdSRPhraseFinishEvent
               read FOnPhraseFinish write FOnPhraseFinish;
      property OnPhraseHypothesis : TApdSRPhraseHypothesisEvent
               read FOnPhraseHypothesis write FOnPhraseHypothesis;
      property OnSpeakStart : TApdSapiNotifyEvent
               read FOnSpeakStart write FOnSpeakStart;
      property OnSpeakStop : TApdSapiNotifyEvent
               read FOnSpeakStop write FOnSpeakStop;
      property OnSRError : TApdOnSapiError read FOnSRError write FOnSRError;
      property OnSRWarning : TApdOnSapiError
               read FOnSRWarning write FOnSRWarning;
      property OnSSAttributeChanged : TApdSSAttributeChanged
               read FOnSSAttributeChanged write FOnSSAttributeChanged;
      property OnSSError : TApdOnSapiError read FOnSSError write FOnSSError;
      property OnSSWarning : TApdOnSapiError

⌨️ 快捷键说明

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