views:

131

answers:

1

the code are not so complecated..

  private
{ Private declarations }
SpSharedRecoContext1 : TSpSharedRecoContext;
fMyGrammar : ISpeechRecoGrammar;
procedure SpSharedRecoContext1Recognition(ASender: TObject; StreamNumber: Integer;
                                                            StreamPosition: OleVariant;
                                                            RecognitionType: SpeechRecognitionType;
                                                            const Result: ISpeechRecoResult);
procedure SpSharedRecoContext1Hypothesis(ASender: TObject; StreamNumber: Integer;
                                                           StreamPosition: OleVariant;
                                                           const Result: ISpeechRecoResult);
procedure TForm1.FormCreate(Sender: TObject);    
begin    
  SpSharedRecoContext1 := TSpSharedRecoContext.Create(self);    
  SpSharedRecoContext1.OnHypothesis := SpSharedRecoContext1Hypothesis;    
  SpSharedRecoContext1.OnRecognition :=SpSharedRecoContext1Recognition;    
  fMyGrammar := SpSharedRecoContext1.CreateGrammar(0);    
  fMyGrammar.DictationSetState(SGDSActive);    
end;    

procedure TForm1.SpSharedRecoContext1Recognition(ASender: TObject; StreamNumber: Integer;
                                                                StreamPosition: OleVariant;
                                                                RecognitionType: SpeechRecognitionType;
                                                                const Result: ISpeechRecoResult);    
begin    
  Memo1.Text := Result.PhraseInfo.GetText(0,-1,true);    
end;    

procedure TForm1.SpSharedRecoContext1Hypothesis(ASender: TObject; StreamNumber: Integer;
                                                               StreamPosition: OleVariant;
                                                               const Result: ISpeechRecoResult);    
begin    
  Memo1.Text := Result.PhraseInfo.GetText(0,-1,true);    
end;  

My Problem, was the vista-OS voice command will intercept on my program. if i say "START", instead of writing start on memo1 it press the start menu on my desktop. or what ever command like START CANCEL EDIT DELETE SELECT etc. please help..... sorry for my english

+1  A: 

You need to use an in-process recognizer, rather than the shared recognizer. Look at the SpInprocRecoContext object.

In particular, you need to also set the AudioInput property of the recognizer, so that the inproc recognizer knows where to get the audio from.

A fully worked example for simple dictation is part of the Windows 7 or Windows Vista SDK - after you install it, it's in $(WindowsSdkDir)\Samples\winui\speech\simpledictation.

The samples are in C++, but you should be able to use that as a launching point.

Eric Brown
I tried to change SpSharedRecoContext to SpInprocRecoContext but it wont detect any voice signals. do you have any simple code?
XBasic3000
Edited answer to be more explicit.
Eric Brown
Ok I see... Thanx It solve the problem. thanx alot. more power!
XBasic3000