MS Speech Server WAV audio file to text error SPERR_NOT_TOPLEVEL_RULE

0

Trying to get MS Speech Server recognize WAV audio file speech and to translate it to text in Delphi XE7 on Windows 7 Professional 64 bit, but get an error 0x80045054 "SPERR_NOT_TOPLEVEL_RULE". Couldn't find nothing about this error. This same code with only 2 different lines works fine with SAPI, but I need different languages support too and only found speech recognition localization files for Speech Server ( https://www.microsoft.com/en-us/download/details.aspx?id=3971 ). Installed MS Speech Server, imported the ActiveX type library in Delphi (SpeechLibServer_TLB.pas) and this is the code:

    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.

Question is how what does this error mean, how to fix it, and why not getting it with Microsoft Speech Object Library (SAPI) but do with MS Speech Server, and how to get this code working with various languages support.

Thank You!

delphi
speech-recognition
wav
asked on Stack Overflow Jan 20, 2019 by 3delite

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0