试图让MS Speech Server识别WAV音频文件语音并将其转换为Windows 7 Professional 64位上的Delphi XE7中的文本,但出现错误0x80045054“ SPERR_NOT_TOPLEVEL_RULE”。 找不到关于此错误的信息。相同的代码只有2条不同的行,可以在SAPI上正常工作,但是我也需要不同的语言支持,并且只能找到语音服务器(https://www.microsoft.com/en-us/download/details.aspx?id=3971)的语音识别本地化文件。 安装了MS Speech Server,在Delphi(SpeechLibServer_TLB.pas)中导入了ActiveX类型库,这是代码:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleServer, SpeechLibServer_TLB, ActiveX;
type
TForm1 = class(TForm)
Button1: TButton;
procedure SPRecognition(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: TOleEnum; const Result: ISpeechRecoResult);
procedure SPFalseRecognition(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; const Result: ISpeechRecoResult);
procedure SPEndStream(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; StreamReleased: WordBool);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FileStream: TSpFileStream;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
SR: TSpInProcRecoContext;
Grammar: ISpeechRecoGrammar;
begin
{
Error 0x80045054
Value: -2147200940 | 0x80045054 | 2147766356
What does it mean?
SPERR_NOT_TOPLEVEL_RULE
An attempt to deactivate or activate a non-toplevel rule.
}
FileStream := TSpFileStream.Create(Self);
SR := TSpInProcRecoContext.Create(Self);
try
SR.OnEndStream := SPEndStream;
SR.OnFalseRecognition := SPFalseRecognition;
SR.OnRecognition := SPRecognition;
Grammar := SR.CreateGrammar(0);
//* British English $809, American English $409, DK = 1030, strange but this line accepts any number even locale IDs that are not installed.
Grammar.Reset($409);
//Grammar.DictationSetState(SGDSActive); //* Error: Not implemented. for Speech Server, accepted for SAPI.
Grammar.State := SGSEnabled; //* Added this line for Speech Server.
FileStream.Open('whatstheweatherlike.wav', SPFM_OPEN_READONLY, False);
SR.Recognizer.AudioInputStream := FileStream.DefaultInterface;
Grammar.CmdSetRuleState('TopRule', SGDSActive); //* Error 0x80045054 An attempt to deactivate or activate a non-toplevel rule.
finally
FreeAndNil(SR);
end;
end;
procedure TForm1.SPEndStream(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; StreamReleased: WordBool);
begin
FileStream.Close;
end;
procedure TForm1.SPFalseRecognition(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; const Result: ISpeechRecoResult);
begin
Showmessage('Cannot recognize');
end;
procedure TForm1.SPRecognition(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: TOleEnum; const Result: ISpeechRecoResult);
begin
Showmessage(Result.PhraseInfo.GetText(0, - 1, True));
end;
end.
问题是这个错误是什么意思,如何解决,为什么不通过Microsoft Speech Object Library(SAPI)来获得它,而是为什么要通过MS Speech Server来获得它,以及如何使该代码在各种语言支持下工作。 / p>
谢谢!