📄 adsapiph.pas
字号:
SpeakingSlower := ApdSpeakingSlower;
TooFewDigits := ApdTooFewDigits;
TooManyDigits := ApdTooManyDigits;
Unrecognized := ApdUnrecognized;
VerifyPost := ApdVerifyPost;
VerifyPre := ApdVerifyPre;
Where := ApdWhere;
Where2 := ApdWhere2;
end;
function TApdSapiPhonePrompts.GenerateExtensionGrammar (
NewTooFewDigits : string;
NewTooManyDigits : string) : string;
begin
Result := '';
if NewTooFewDigits <> '' then
Result := Result + 'TooFewDigits=' + NewTooFewDigits + ^M^J
else if TooFewDigits <> '' then
Result := Result + 'TooFewDigits=' + TooFewDigits + ^M^J;
if NewTooManyDigits <> '' then
Result := Result + 'TooManyDigits=' + NewTooManyDigits + ^M^J
else if TooManyDigits <> '' then
Result := Result + 'TooManyDigits =' + TooManyDigits + ^M^J;
end;
function TApdSapiPhonePrompts.GenerateGrammar (NewPrompt1 : string;
NewPrompt2 : string;
NewHelp1 : string;
NewHelp2 : string;
NewWhere1 : string;
NewWhere2 : string) : string;
begin
Result := '[Prompts]'^M^J;
if NewPrompt1 <> '' then
Result := Result + 'Main=' + NewPrompt1 + ^M^J
else if Main <> '' then
Result := Result + 'Main=' + Main + ^M^J;
if NewPrompt2 <> '' then
Result := Result + 'Main.2=' + NewPrompt2 + ^M^J
else if Main2 <> '' then
Result := Result + 'Main=' + Main2 + ^M^J;
if NewWhere1 <> '' then
Result := Result + 'Where=' + NewWhere1 + ^M^J
else if Where <> '' then
Result := Result + 'Where=' + Where + ^M^J;
if NewWhere2 <> '' then
Result := Result + 'Where.2=' + NewWhere2 + ^M^J
else if Where2 <> '' then
Result := Result + 'Where.2=' + Where2 + ^M^J;
if NewHelp1 <> '' then
Result := Result + 'Help=' + NewHelp1 + ^M^J
else if Help <> '' then
Result := Result + 'Help=' + Help + ^M^J;
if NewHelp2 <> '' then
Result := Result + 'Help.2=' + NewHelp2+ ^M^J
else if Help2 <> '' then
Result := Result + 'Help.2=' + Help2 + ^M^J;
end;
function TApdSapiPhonePrompts.GeneratePhoneNumberGrammar (
NewAskAreaCode : string;
NewAskNextThree : string;
NewAskLastFour : string) : string;
begin
Result := '';
if NewAskAreaCode <> '' then
Result := Result + 'AskAreaCode =' + NewAskAreaCode + ^M^J
else if AskAreaCode <> '' then
Result := Result + 'AskAreaCode =' + AskAreaCode + ^M^J;
if NewAskNextThree <> '' then
Result := Result + 'AskNextThree =' + NewAskNextThree + ^M^J
else if AskNextThree <> '' then
Result := Result + 'AskNextThree =' + AskNextThree + ^M^J;
if NewAskLastFour <> '' then
Result := Result + 'AskLastFour =' + NewAskLastFour + ^M^J
else if AskLastFour <> '' then
Result := Result + 'AskLastFour =' + AskLastFour + ^M^J;
end;
procedure TApdSapiPhonePrompts.SetAskAreaCode (v : string);
begin
if v <> FAskAreaCode then
FAskAreaCode := v;
end;
procedure TApdSapiPhonePrompts.SetAskLastFour (v : string);
begin
if v <> FAskLastFour then
FAskLastFour := v;
end;
procedure TApdSapiPhonePrompts.SetAskNextThree (v : string);
begin
if v <> FAskNextThree then
FAskNextThree := v;
end;
procedure TApdSapiPhonePrompts.SetCannotGoBack (v : string);
begin
if v <> FCannotGoBack then
FCannotGoBack := v;
end;
procedure TApdSapiPhonePrompts.SetCannotHangUp (v : string);
begin
if v <> FCannotHangUp then
FCannotHangUp := v;
end;
procedure TApdSapiPhonePrompts.SetGoingBack (v : string);
begin
if v <> FGoingBack then
FGoingBack := v;
end;
procedure TApdSapiPhonePrompts.SetHangingUp (v : string);
begin
if v <> FHangingUp then
FHangingUp := v;
end;
procedure TApdSapiPhonePrompts.SetHelp (v : string);
begin
if v <> FHelp then
FHelp := v;
end;
procedure TApdSapiPhonePrompts.SetHelp2 (v : string);
begin
if v <> FHelp2 then
FHelp2 := v;
end;
procedure TApdSapiPhonePrompts.SetHelpVerify (v : string);
begin
if v <> FHelpVerify then
FHelpVerify := v;
end;
procedure TApdSapiPhonePrompts.SetMain (v : string);
begin
if v <> FMain then
FMain := v;
end;
procedure TApdSapiPhonePrompts.SetMain2 (v : string);
begin
if v <> FMain2 then
FMain2 := v;
end;
procedure TApdSapiPhonePrompts.SetMaxSpeed (v : string);
begin
if v <> FMaxSpeed then
FMaxSpeed := v;
end;
procedure TApdSapiPhonePrompts.SetMinSpeed (v : string);
begin
if v <> FMinSpeed then
FMinSpeed := v;
end;
procedure TApdSapiPhonePrompts.SetOperator (v : string);
begin
if v <> FOperator then
FOperator := v;
end;
procedure TApdSapiPhonePrompts.SetNoOperator (v : string);
begin
if v <> FNoOperator then
FNoOperator := v;
end;
procedure TApdSapiPhonePrompts.SetNoSpeedChange (v : string);
begin
if v <> FNoSpeedChange then
FNoSpeedChange := v;
end;
procedure TApdSapiPhonePrompts.SetSpeakingFaster (v : string);
begin
if v <> FSpeakingFaster then
FSpeakingFaster := v;
end;
procedure TApdSapiPhonePrompts.SetSpeakingSlower (v : string);
begin
if v <> FSpeakingSlower then
FSpeakingSlower := v;
end;
procedure TApdSapiPhonePrompts.SetTooFewDigits (v : string);
begin
if v <> FTooFewDigits then
FTooFewDigits := v;
end;
procedure TApdSapiPhonePrompts.SetTooManyDigits (v : string);
begin
if v <> FTooManyDigits then
FTooManyDigits := v;
end;
procedure TApdSapiPhonePrompts.SetUnrecognized (v : string);
begin
if v <> FUnrecognized then
FUnrecognized := v;
end;
procedure TApdSapiPhonePrompts.SetVerifyPost (v : string);
begin
if v <> FVerifyPost then
FVerifyPost := v;
end;
procedure TApdSapiPhonePrompts.SetVerifyPre (v : string);
begin
if v <> FVerifyPre then
FVerifyPre := v;
end;
procedure TApdSapiPhonePrompts.SetWhere (v : string);
begin
if v <> FWhere then
FWhere := v;
end;
procedure TApdSapiPhonePrompts.SetWhere2 (v : string);
begin
if v <> FWhere2 then
FWhere2 := v;
end;
{ TApdSapiAskForInfo }
constructor TApdSapiAskForInfo.Create;
begin
inherited Create;
FAskForGrammar := TStringList.Create;
FMainGrammar := TStringList.Create;
FPrompts := TApdSapiPhonePrompts.Create;
FStringHandler := gshIgnore;
InitializeMainGrammar;
end;
destructor TApdSapiAskForInfo.Destroy;
begin
FAskForGrammar.Free;
FMainGrammar.Free;
FPrompts.Free;
inherited Destroy;
end;
procedure TApdSapiAskForInfo.AskFor;
begin
if not Assigned (FSapiEngine) then
raise ESapiPhoneError.Create (-1, ecApdNoSapiEngine);
if not Assigned (FPrompts) then
raise ESapiPhoneError.Create (-1, ecApdNoPrompts);
FSapiEngine.RegisterPhraseFinishHook (SapiPhraseFinishHook);
FSapiEngine.Speak (Prompts.Main);
FSapiEngine.DirectSR.GrammarFromString (FMainGrammar.Text + ^M^J +
FAskForGrammar.Text);
FSapiEngine.Listening := True;
end;
function TApdSapiAskForInfo.DeterminePhraseType (Phrase : string) : TApdPhraseType;
var
PhraseType : string;
begin
Result := DeterminePhraseTypeEx (Phrase, PhraseType);
end;
function TApdSapiAskForInfo.DeterminePhraseTypeEx (Phrase : string;
var Rule : string) : TApdPhraseType;
begin
Result := ptUnknown;
Rule := FindGrammarRule (Phrase);
if Rule = '' then begin
Result := ptNone;
Exit;
end;
try
case StrToInt (Rule) of
-3 : Result := ptOperator;
-4 : Result := ptHangup;
-5 : Result := ptBack;
-10 : Result := ptWhere;
-11 : Result := ptHelp;
-12 : Result := ptRepeat;
-13 : Result := ptSpeakFaster;
-14 : Result := ptSpeakSlower;
end;
except
on EConvertError do
begin
end;
end;
end;
function TApdSapiAskForInfo.GetKey (Value : string) : string;
{ Returns the Key portion of <Key>=<Value> }
var
Sep : Integer;
begin
Result := '';
Sep := Pos ('=', Value);
if Sep > 1 then
Result := Copy (Value, 1, Sep - 1);
end;
function TApdSapiAskForInfo.GetValue (Value : string) : string;
{ Returns the Value portion of <Key>=<Value> }
var
Sep : Integer;
begin
Result := '';
Sep := Pos ('=', Value);
if Sep > 0 then
Result := Copy (Value, Sep + 1, Length (Value) - Sep)
end;
function TApdSapiAskForInfo.IsAnglePhrase (Phrase : string) : Boolean;
begin
Result := False;
if Phrase = '' then
Exit;
if (Phrase[1] = '<') and (Phrase[Length (Phrase)] = '>') then
Result := True;
end;
function TApdSapiAskForInfo.IsParenPhrase (Phrase : string) : Boolean;
begin
Result := False;
if Phrase = '' then
Exit;
if (Phrase[1] = '(') and (Phrase[Length (Phrase)] = ')') then
Result := True;
end;
function TApdSapiAskForInfo.IsQuoted (Phrase : string) : Boolean;
begin
Result := False;
if Phrase = '' then
Exit;
if (Phrase[1] = '"') and (Phrase[Length (Phrase)] = '"') then
Result := True;
end;
function TApdSapiAskForInfo.KillQuotes (Phrase : string) : string;
begin
Result := Phrase;
if IsQuoted (Phrase) then
Result := Copy (Phrase, 2, Length (Phrase) - 2);
end;
function TApdSapiAskForInfo.AnalyzeRule (Tokens : TStringList;
CurrentRule : string;
INIFile : TApdSapiGrammarList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -