Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: VB to Delphi Translation

  1. #11
    Variable Bitrate
    Join Date
    Jan 2005
    Location
    UK
    Posts
    265
    Quote Originally Posted by 0l33l
    [code]Same thing... and I create the Phrases and call creategrammar. It fails when I press the button.
    Are you getting the fail in the call to CmdSetRuleIdState I mentioned in post #6? It's an OLE error. If so, I'm as stuck as you are.

    Ric.

  2. #12
    My Village Called 0l33l's Avatar
    Join Date
    Jul 2004
    Location
    Berkeley, CA
    Posts
    10,516
    Quote Originally Posted by ric355
    Are you getting the fail in the call to CmdSetRuleIdState I mentioned in post #6? It's an OLE error. If so, I'm as stuck as you are.

    Ric.
    When mine fails its at Rule.InitialState.AddWordTransition(Nil, word, ' ', SPWT_LEXICAL, 'value',1,value,1.0);

  3. #13
    Variable Bitrate
    Join Date
    Jan 2005
    Location
    UK
    Posts
    265
    Quote Originally Posted by 0l33l
    When mine fails its at Rule.InitialState.AddWordTransition(Nil, word, ' ', SPWT_LEXICAL, 'value',1,value,1.0);
    You haven't said what the error is, but if it's an access violation then that's probably because of the line Rule:=nil in CreateGrammar. Take it out. AddWord uses Rule, and Rule will be nil by the time you press your button.

    Really those global variables ought to be class variables so they can be tidied up with the form class on shutdown.

  4. #14
    My Village Called 0l33l's Avatar
    Join Date
    Jul 2004
    Location
    Berkeley, CA
    Posts
    10,516
    Code:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, SpeechLib_TLB, OleServer, StdCtrls;
    
    type
      TForm1 = class(TForm)
        SpSharedRecoContext1: TSpSharedRecoContext;
        Button1: TButton;
        Button2: TButton;
        procedure SpSharedRecoContext1Hypothesis(ASender: TObject;
          StreamNumber: Integer; StreamPosition: OleVariant;
          const Result: ISpeechRecoResult);
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure CreateGrammar;
        procedure AddWord(word: String);
      end;
    
    var
      Form1: TForm1;
      SRGrammar: ISpeechRecoGrammar;
      Rule: ISpeechGrammarRule;
      WordNumber: Integer;
    
      // Create this object and fill it with the words
      // or phrases you want to recognise before calling CreateGrammar
      Phrases: TStringList;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.SpSharedRecoContext1Hypothesis(ASender: TObject;
      StreamNumber: Integer; StreamPosition: OleVariant;
      const Result: ISpeechRecoResult);
    var text: String; confidence: Integer;
    begin
    text:=Result.PhraseInfo.GetText(0,-1,True);
    Confidence:=Integer(Result.PhraseInfo.Rule.Confidence);
    showmessage(text);
    end;
    
    procedure TForm1.AddWord(word: String);
    Var Value: OleVariant;
    begin
      Inc(WordNumber);
      Value:=WordNumber;
      Rule.InitialState.AddWordTransition(Nil, word, ' ', SPWT_LEXICAL, 'value',1,value,1.0);
    end;
    
    procedure TForm1.CreateGrammar;
    var
    i : integer;
    begin
      //OnAudioLevel event is not fired by default - this changes that
      SpSharedRecoContext1.EventInterests := SREAllEvents;
      SRGrammar := SpSharedRecoContext1.CreateGrammar(0);
      Rule:=SRGrammar.Rules.Add('word',SRATopLevel+SRADefaultToActive,0);
      WordNumber:=0;
      for i := 0 to Phrases.Count-1 do begin
        AddWord(Phrases[i]);
      end;
      //Rule:=Nil;
      SRGrammar.Rules.Commit;
      SRGrammar.CmdSetRuleIdState(0, SGDSActive);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    //addword('test');
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Phrases := TStringList.Create;
    Phrases.Add('testing');
    Phrases.Add('hi');
    CreateGrammar;
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
    //addword('hi');
    end;
    
    end.


    Sweet! That works now
    Now I just have to figure out how to suit it for my needs

    Thanks ric355!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. developing in VB
    By ShinkunoNamida in forum Software & Software Development
    Replies: 17
    Last Post: 07-27-2008, 10:13 AM
  2. Delphi SDK examples?
    By Nisos in forum FreeDrive
    Replies: 11
    Last Post: 04-23-2005, 05:22 PM
  3. advice for starting out in VB programming
    By Vchat20 in forum Software & Software Development
    Replies: 10
    Last Post: 02-06-2005, 01:00 PM
  4. Using VB to search and play a track in Winamp
    By deadweasel in forum Software & Software Development
    Replies: 23
    Last Post: 01-26-2004, 06:25 PM
  5. Developing a VB app with IR input???
    By mp3stang02 in forum Software & Software Development
    Replies: 8
    Last Post: 08-26-2002, 12:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •