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

📄 adsapien.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    if (v and ApdSRFEATURE_TRAINPHONETIC) <> 0 then
      Result := Result + [sfTrainPhonetic];
    if (v and ApdSRFEATURE_WILDCARD) <> 0 then
      Result := Result + [sfWildcard];
    if (v and ApdSRFEATURE_ANYWORD) <> 0 then
      Result := Result + [sfAnyWord];
    if (v and ApdSRFEATURE_PCOPTIMIZED) <> 0 then
      Result := Result + [sfPCOptimized];
    if (v and ApdSRFEATURE_PHONEOPTIMIZED) <> 0 then
      Result := Result + [sfPhoneOptimized];
    if (v and ApdSRFEATURE_GRAMLIST) <> 0 then
      Result := Result + [sfGramList];
    if (v and ApdSRFEATURE_GRAMLINK) <> 0 then
      Result := Result + [sfGramLink];
    if (v and ApdSRFEATURE_MULTILINGUAL) <> 0 then
      Result := Result + [sfMultiLingual];
    if (v and ApdSRFEATURE_GRAMRECURSIVE) <> 0 then
      Result := Result + [sfGramRecursive];
    if (v and ApdSRFEATURE_IPAUNICODE) <> 0 then
      Result := Result + [sfIPAUnicode];
    if (v and ApdSRFEATURE_SINGLEINSTANCE) <> 0 then
      Result := Result + [sfSingleInstance];
    if (v and ApdSRFEATURE_THREADSAFE) <> 0 then
      Result := Result + [sfThreadSafe];
    if (v and ApdSRFEATURE_FIXEDAUDIO) <> 0 then
      Result := Result + [sfFixedAudio];
    if (v and ApdSRFEATURE_IPAWORD) <> 0 then
      Result := Result + [sfIPAWord];
    if (v and ApdSRFEATURE_SAPI4) <> 0 then
      Result := Result + [sfSAPI4];
  end;

begin
  CheckIndex (x);
  Result := ConvertFeatures (FiDirectSR.Features (x + 1));
end;

function TApdSREngines.GetGrammars (x : Integer) : TApdSRGrammars;

  function ConvertGrammars (v : Integer) : TApdSRGrammars;
  begin
    Result := [];
    if (v and ApdSRGRAM_CFG) <> 0 then
      Result := Result + [sgCFG];
    if (v and ApdSRGRAM_DICTATION) <> 0 then
      Result := Result + [sgDictation];
    if (v and ApdSRGRAM_LIMITEDDOMAIN) <> 0 then
      Result := Result + [sgLimitedDomain];
  end;

begin
  CheckIndex (x);
  Result := ConvertGrammars (FiDirectSR.Grammars (x + 1));
end;

function TApdSREngines.GetInterfaces (x : Integer) : TApdSRInterfaces;

  function ConvertInterfaces (v : Integer) : TApdSRInterfaces;
  begin
    Result := [];
    if (v and ApdSRI_ILEXPRONOUNCE) <> 0 then
      Result := Result + [siLexPronounce];
    if (v and ApdSRI_ISRATTRIBUTES) <> 0 then
      Result := Result + [siSRAttributes];
    if (v and ApdSRI_ISRCENTRAL) <> 0 then
      Result := Result + [siSRCentral];
    if (v and ApdSRI_ISRDIALOGS) <> 0 then
      Result := Result + [siSRDialogs];
    if (v and ApdSRI_ISRGRAMCOMMON) <> 0 then
      Result := Result + [siSRGramCommon];
    if (v and ApdSRI_ISRGRAMCFG) <> 0 then
      Result := Result + [siSRGramCFG];
    if (v and ApdSRI_ISRGRAMDICTATION) <> 0 then
      Result := Result + [siSRGramDictation];
    if (v and ApdSRI_ISRGRAMINSERTIONGUI) <> 0 then
      Result := Result + [siSRGramInsertionGui];
    if (v and ApdSRI_ISRESBASIC) <> 0 then
      Result := Result + [siSREsBasic];
    if (v and ApdSRI_ISRESMERGE) <> 0 then
      Result := Result + [siSREsMerge];
    if (v and ApdSRI_ISRESAUDIO) <> 0 then
      Result := Result + [siSREsAudio];
    if (v and ApdSRI_ISRESCORRECTION) <> 0 then
      Result := Result + [siSREsCorrection];
    if (v and ApdSRI_ISRESEVAL) <> 0 then
      Result := Result + [siSREsEval];
    if (v and ApdSRI_ISRESGRAPH) <> 0 then
      Result := Result + [siSREsGraph];
    if (v and ApdSRI_ISRESMEMORY) <> 0 then
      Result := Result + [siSREsMemory];
    if (v and ApdSRI_ISRESMODIFYGUI) <> 0 then
      Result := Result + [siSREsModifyGui];
    if (v and ApdSRI_ISRESSPEAKER) <> 0 then
      Result := Result + [siSREsSpeaker];
    if (v and ApdSRI_ISRSPEAKER) <> 0 then
      Result := Result + [siSRSpeaker];
    if (v and ApdSRI_ISRESSCORES) <> 0 then
      Result := Result + [siSREsScores];
    if (v and ApdSRI_ISRESAUDIOEX) <> 0 then
      Result := Result + [siSREsAudioEx];
    if (v and ApdSRI_ISRGRAMLEXPRON) <> 0 then
      Result := Result + [siSRGramLexPron];
    if (v and ApdSRI_ISRRESGRAPHEX) <> 0 then
      Result := Result + [siSREsGraphEx];
    if (v and ApdSRI_ILEXPRONOUNCE2) <> 0 then
      Result := Result + [siLexPronounce2];
    if (v and ApdSRI_IATTRIBUTES) <> 0 then
      Result := Result + [siAttributes];
    if (v and ApdSRI_ISRSPEAKER2) <> 0 then
      Result := Result + [siSRSpeaker2];
    if (v and ApdSRI_ISRDIALOGS2) <> 0 then
      Result := Result + [siSRDialogs2];
  end;

begin
  CheckIndex (x);
  Result := ConvertInterfaces (FiDirectSR.Interfaces (x + 1));
end;

function TApdSREngines.GetLanguageID (x : Integer) : Integer;
begin
  CheckIndex (x);
  Result := FiDirectSR.LanguageID (x + 1);
end;

function TApdSREngines.GetMaxWordsState (x : Integer) : Integer;
begin
  CheckIndex (x);
  Result := FiDirectSR.MaxWordsState (x + 1);
end;

function TApdSREngines.GetMaxWordsVocab (x : Integer) : Integer;
begin
  CheckIndex (x);
  Result := FiDirectSR.MaxWordsVocab (x + 1);
end;

function TApdSREngines.GetMfgName (x : Integer) : string;
begin
  CheckIndex (x);
  Result := FiDirectSR.MfgName (x + 1);
end;

function TApdSREngines.GetModeID (x : Integer) : string;
begin
  CheckIndex (x);
  Result := FiDirectSR.ModeID (x + 1);
end;

function TApdSREngines.GetModeName (x : Integer) : string;
begin
  CheckIndex (x);
  Result := FiDirectSR.ModeName (x + 1);
end;

function TApdSREngines.GetProductName (x : Integer) : string;
begin
  CheckIndex (x);
  Result := FiDirectSR.ProductName (x + 1);
end;

function TApdSREngines.GetSequencing (x : Integer) : TApdSRSequences;

  function ConvertSequencing (v : Integer) : TApdSRSequences;
  begin
    case v of
      ApdSRSEQUENCE_DISCRETE        : Result := ssDiscrete;
      ApdSRSEQUENCE_CONTINUOUS      : Result := ssContinuous;
      ApdSRSEQUENCE_WORDSPOT        : Result := ssWordSpot;
      ApdSRSEQUENCE_CONTCFGDISCDICT : Result := ssContCFGDiscDict;
    else
      Result := ssUnknown;
    end;
  end;

begin
  CheckIndex (x);
  Result := ConvertSequencing (FiDirectSR.Sequencing (x + 1));
end;

procedure TApdSREngines.SetCurrentEngine (v : Integer);
begin
  if v <> FCurrentEngine then begin
    CheckIndex (v);
    FiDirectSR.Select (v + 1);
    FCurrentEngine := v;
  end;
end;

{ TApdCustomSapiEngine }                     

constructor TApdCustomSapiEngine.Create (AOwner : TComponent);
begin
  inherited Create (AOwner);

  FInitSR := True;                                                     {!!.04}
  FInitSS := True;                                                     {!!.04}

  FHandle := AllocateHWnd (WndProc);

  (*if not IsSapi4Installed then begin                                 {!!.04}
    if Assigned (FOnSRError) then                                      {!!.04}
      FOnSRError (Self, 0, '', ApdStrE_NOSAPI4);                       {!!.04}
    if Assigned (FOnSSError) then                                      {!!.04}
      FOnSSError (Self, 0, '', ApdStrE_NOSAPI4);                       {!!.04}
  end; *)                                                              {!!.04}

  FSpeaking := False;
  FListening := False;
  FDuplex := sdHalfDelayed;
  FWaitMode := wmNone;

  { Create needed classes }

  FWordList := TStringList.Create;
  FSSVoices := TApdSSVoices.Create;
  FSREngines := TApdSREngines.Create;

  { Create Registers }

  FPhraseFinishClients := TList.Create;

  FiDirectSS := nil;
  FiDirectSR := nil;

  FAutoTrain := False;
end;

destructor TApdCustomSapiEngine.Destroy;
var
  i : Integer;
  
begin
  FWordList.Free;

  FSSVoices.Free;
  FSREngines.Free;

  for i := 0 to FPhraseFinishClients.Count - 1 do begin
    Dispose (FPhraseFinishClients[i]);
  end;
  FPhraseFinishClients.Free;

  if Assigned (FiDirectSS) then
    FiDirectSS.Free;
  if Assigned (FiDirectSR) then
    FiDirectSR.Free;

  if FHandle <> 0 then
    DeallocateHWnd (FHandle);
  inherited Destroy;
end;

procedure TApdCustomSapiEngine.CheckError (ErrorCode : DWORD);
begin
  case ErrorCode of
    ApdSRERR_NONE                       :
      begin
      end;

  { SS }

    ApdTTSERR_INVALIDINTERFACE          :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_INVALIDINTERFACE);
    ApdTTSERR_OUTOFDISK                 :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_OUTOFDISK);
    ApdTTSERR_NOTSUPPORTED              :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_NOTSUPPORTED);
    ApdTTSERR_VALUEOUTOFRANGE           :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_VALUEOUTOFRANGE);
    ApdTTSERR_INVALIDWINDOW             :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_INVALIDWINDOW);
    ApdTTSERR_INVALIDPARAM              :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_INVALIDPARAM);
    ApdTTSERR_INVALIDMODE               :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_INVALIDMODE);
    ApdTTSERR_INVALIDKEY                :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_INVALIDKEY);
    ApdTTSERR_WAVEFORMATNOTSUPPORTED    :
      raise EApdSapiEngineException.Create (ErrorCode,
                                          ApdStrTTSERR_WAVEFORMATNOTSUPPORTED);
    ApdTTSERR_INVALIDCHAR               :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_INVALIDCHAR);
    ApdTTSERR_QUEUEFULL                 :
      raise EApdSapiEngineException.Create (ErrorCode, ApdStrTTSERR_QUEUEFULL);
    ApdTTSERR_WAVEDEVICEBUSY            :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_WAVEDEVICEBUSY);
    ApdTTSERR_NOTPAUSED                 :
      raise EApdSapiEngineException.Create (ErrorCode, ApdStrTTSERR_NOTPAUSED);
    ApdTTSERR_ALREADYPAUSED             :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrTTSERR_ALREADYPAUSED);

  { SR }

    ApdSRERR_NOTENOUGHDATA              :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_NOTENOUGHDATA);
    ApdSRERR_GRAMMARTOOCOMPLEX          :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_GRAMMARTOOCOMPLEX);
    ApdSRERR_GRAMMARWRONGTYPE           :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_GRAMMARWRONGTYPE);
    ApdSRERR_TOOMANYGRAMMARS            :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_INVALIDLIST);
    ApdSRERR_INVALIDLIST                :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_INVALIDLIST);
    ApdSRERR_GRAMTOOLARGE               :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_GRAMTOOLARGE);
    ApdSRERR_INVALIDFLAG                :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_INVALIDFLAG);
    ApdSRERR_GRAMMARERROR               :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_GRAMMARERROR);
    ApdSRERR_INVALIDRULE                :
      raise EApdSapiEngineException.Create (ErrorCode,
                                            ApdStrSRERR_INVALIDRULE);

⌨️ 快捷键说明

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