📄 adsapien.pas
字号:
read FOnSSWarning write FOnSSWarning;
property OnTrainingRequested : TApdSRTrainingRequestedEvent
read FOnTrainingRequested write FOnTrainingRequested;
property OnVUMeter : TApdSRVUMeterEvent
read FOnVUMeter write FOnVUMeter;
end;
TApdSapiEngine = class (TApdCustomSapiEngine)
published
property CharSet;
property Dictation;
property SRAmplitude;
property SRAutoGain;
property TTSOptions;
property WordList;
property OnInterference;
property OnPhraseFinish;
property OnPhraseHypothesis;
property OnSpeakStart;
property OnSpeakStop;
property OnSRError;
property OnSRWarning;
property OnSSAttributeChanged;
property OnSSError;
property OnSSWarning;
property OnTrainingRequested;
property OnVUMeter;
end;
{.Z+}
function SearchSapiEngine (const C : TComponent) : TApdCustomSapiEngine;
{.Z-}
implementation
{Miscellaneous procedures}
function SearchSapiEngine (const C : TComponent) : TApdCustomSapiEngine;
{-Search for a sapi engine in the same form as TComponent}
function FindSapiEngine (const C : TComponent) : TApdCustomSapiEngine;
var
I : Integer;
begin
Result := nil;
if not Assigned (C) then
Exit;
{Look through all of the owned components}
for I := 0 to C.ComponentCount - 1 do begin
if C.Components[I] is TApdCustomSapiEngine then begin
Result := TApdCustomSapiEngine (C.Components[I]);
Exit;
end;
{If this isn't one, see if it owns other components}
Result := FindSapiEngine (C.Components[I]);
end;
end;
begin
{Search the entire form}
Result := FindSapiEngine (C);
end;
{ EApdSapiEngineException }
constructor EApdSapiEngineException.Create (const ErrCode : Integer;
const Msg : string);
begin
inherited Create (Msg);
FErrorCode := ErrCode;
end;
{ TApdSSVoices }
function TApdSSVoices.CheckIndex (x : Integer) : Boolean;
begin
if not Assigned (FiDirectSS) then
raise EApdSapiEngineException.CreateFmt (ecApdNOSS, [0]);
if (x < 0) or (x >= FiDirectSS.CountEngines) then
raise EApdSapiEngineException.CreateFmt (ecApdBadIndex, [0]);
Result := True;
end;
function TApdSSVoices.Find (Criteria : string) : Integer;
begin
Result := FiDirectSS.Find (Criteria);
end;
function TApdSSVoices.GetAge (x : Integer) : TApdTTSAge;
function ConvertAge (v : Integer) : TApdTTSAge;
begin
case v of
ApdTTSAGE_BABY : Result := tsBaby;
ApdTTSAGE_TODDLER : Result := tsToddler;
ApdTTSAGE_CHILD : Result := tsChild;
ApdTTSAGE_ADOLESCENT : Result := tsAdolescent;
ApdTTSAGE_ADULT : Result := tsAdult;
ApdTTSAGE_ELDERLY : Result := tsElderly;
else
Result := tsUnknown;
end;
end;
begin
CheckIndex (x);
Result := ConvertAge (FiDirectSS.Age (x + 1));
end;
function TApdSSVoices.GetCount : Integer;
begin
Result := FiDirectSS.CountEngines;
end;
function TApdSSVoices.GetCurrentVoice : Integer;
begin
result := FCurrentVoice;
end;
function TApdSSVoices.GetDialect (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.Dialect (x + 1);
end;
function TApdSSVoices.GetEngineFeatures (x : Integer) : Integer;
begin
CheckIndex (x);
Result := FiDirectSS.EngineFeatures (x + 1);
end;
function TApdSSVoices.GetEngineID (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.EngineID (x + 1);
end;
function TApdSSVoices.GetFeatures (x : Integer) : TApdTTSFeatures;
function ConvertFeatures (v : Integer) : TApdTTSFeatures;
begin
Result := [];
if (v and ApdTTSFEATURE_ANYWORD) <> 0 then
Result := Result + [tfAnyWord];
if (v and ApdTTSFEATURE_VOLUME) <> 0 then
Result := Result + [tfVolume];
if (v and ApdTTSFEATURE_SPEED) <> 0 then
Result := Result + [tfSpeed];
if (v and ApdTTSFEATURE_PITCH) <> 0 then
Result := Result + [tfPitch];
if (v and ApdTTSFEATURE_TAGGED) <> 0 then
Result := Result + [tfTagged];
if (v and ApdTTSFEATURE_IPAUNICODE) <> 0 then
Result := Result + [tfIPAUnicode];
if (v and ApdTTSFEATURE_VISUAL) <> 0 then
Result := Result + [tfVisual];
if (v and ApdTTSFEATURE_WORDPOSITION) <> 0 then
Result := Result + [tfWordPosition];
if (v and ApdTTSFEATURE_PCOPTIMIZED) <> 0 then
Result := Result + [tfPCOptimized];
if (v and ApdTTSFEATURE_PHONEOPTIMIZED) <> 0 then
Result := Result + [tfPhoneOptimized];
if (v and ApdTTSFEATURE_FIXEDAUDIO) <> 0 then
Result := Result + [tfFixedAudio];
if (v and ApdTTSFEATURE_SINGLEINSTANCE) <> 0 then
Result := Result + [tfSingleInstance];
if (v and ApdTTSFEATURE_THREADSAFE) <> 0 then
Result := Result + [tfThreadSafe];
if (v and ApdTTSFEATURE_IPATEXTDATA) <> 0 then
Result := Result + [tfIPATextData];
if (v and ApdTTSFEATURE_PREFERRED) <> 0 then
Result := Result + [tfPreferred];
if (v and ApdTTSFEATURE_TRANSPLANTED) <> 0 then
Result := Result + [tfTransplanted];
if (v and ApdTTSFEATURE_SAPI4) <> 0 then
Result := Result + [tfSAPI4];
end;
begin
CheckIndex (x);
Result := ConvertFeatures (FiDirectSS.Features (x + 1));
end;
function TApdSSVoices.GetGender (x : Integer) : TApdTTSGender;
function ConvertGender (v : Integer) : TApdTTSGender;
begin
case v of
ApdGENDER_NEUTRAL : Result := tgNeutral;
ApdGENDER_FEMALE : Result := tgFemale;
ApdGENDER_MALE : Result := tgMale;
else
Result := tgUnknown;
end;
end;
begin
CheckIndex (x);
Result := ConvertGender (FiDirectSS.Gender (x + 1));
end;
function TApdSSVoices.GetInterfaces (x : Integer) : TApdTTSInterfaces;
function ConvertInterfaces (v : Integer) : TApdTTSInterfaces;
begin
Result := [];
if (v and ApdTTSI_ILEXPRONOUNCE) <> 0 then
Result := Result + [tiLexPronounce];
if (v and ApdTTSI_ITTSATTRIBUTES) <> 0 then
Result := Result + [tiTTSAttributes];
if (v and ApdTTSI_ITTSCENTRAL) <> 0 then
Result := Result + [tiTTSCentral];
if (v and ApdTTSI_ITTSDIALOGS) <> 0 then
Result := Result + [tiTTSDialogs];
if (v and ApdTTSI_ATTRIBUTES) <> 0 then
Result := Result + [tiAttributes];
if (v and ApdTTSI_IATTRIBUTES) <> 0 then
Result := Result + [tiIAttributes];
if (v and ApdTTSI_ILEXPRONOUNCE2) <> 0 then
Result := Result + [tiLexPronounce2];
end;
begin
CheckIndex (x);
Result := ConvertInterfaces (FiDirectSS.Interfaces (x + 1));
end;
function TApdSSVoices.GetLanguageID (x : Integer) : Integer;
begin
CheckIndex (x);
Result := FiDirectSS.LanguageID (x + 1);
end;
function TApdSSVoices.GetMfgName (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.MfgName (x + 1);
end;
function TApdSSVoices.GetModeID (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.ModeID (x + 1);
end;
function TApdSSVoices.GetModeName (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.ModeName (x + 1);
end;
function TApdSSVoices.GetProductName (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.ProductName (x + 1);
end;
function TApdSSVoices.GetSpeaker (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.Speaker (x + 1);
end;
function TApdSSVoices.GetStyle (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSS.Style (x + 1);
end;
procedure TApdSSVoices.SetCurrentVoice (v : Integer);
begin
if v <> FCurrentVoice then begin
CheckIndex (v);
FiDirectSS.Select (v + 1);
FCurrentVoice := v;
end;
end;
{ TApdSREngines }
function TApdSREngines.CheckIndex (x : Integer) : Boolean;
begin
if not Assigned (FiDirectSR) then
raise EApdSapiEngineException.CreateFmt (ecApdNoSR, [0]);
if (x < 0) or (x >= FiDirectSR.CountEngines) then
raise EApdSapiEngineException.CreateFmt (ecApdBadIndex, [0]);
Result := True;
end;
function TApdSREngines.GetCount : Integer;
begin
Result := FiDirectSR.CountEngines;
end;
function TApdSREngines.GetCurrentEngine : Integer;
begin
Result := FCurrentEngine;
end;
function TApdSREngines.GetDialect (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSR.Dialect (x + 1);
end;
function TApdSREngines.GetEngineFeatures (x : Integer) : Integer;
begin
CheckIndex (x);
Result := FiDirectSR.EngineFeatures (x + 1);
end;
function TApdSREngines.GetEngineId (x : Integer) : string;
begin
CheckIndex (x);
Result := FiDirectSR.EngineId (x + 1);
end;
function TApdSREngines.GetFeatures (x : Integer) : TApdSRFeatures;
function ConvertFeatures (v : Integer) : TApdSRFeatures;
begin
Result := [];
if (v and ApdSRFEATURE_INDEPSPEAKER) <> 0 then
Result := Result + [sfIndepSpeaker];
if (v and ApdSRFEATURE_INDEPMICROPHONE) <> 0 then
Result := Result + [sfIndepMicrophone];
if (v and ApdSRFEATURE_TRAINWORD) <> 0 then
Result := Result + [sfTrainWord];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -