Delphi How To Use Microsoft Speech Recognition API

Viewed 2265

I need some help with my code, my application supposed to get my voice and write everything i say in a TMemo component, but it's simply doesn't do anything Here is my code: Am using SAPI 5.4 Microsoft Speech Object Library

procedure TForm1.initRecognizer;
begin
    // Create Voice Handler
    SpVoice := TSpVoice.Create(nil);
    //**//
    // Create Reconizer Context
    SpInProcRecoContext := TSpInProcRecoContext.Create(nil);
    SpInProcRecoContext.OnHypothesis  := SpInProcRecoContextHypothesis;
    SpInProcRecoContext.OnRecognition := SpInProcRecoContextRecognition;
    //**//
    // Create Grammar Rule
    RecoGrammar := SpInProcRecoContext.CreateGrammar(0);
    RecoGrammar.DictationSetState(SGDSActive);
    //**//
end;

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

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

Please If there's a fix Will appreciate it, thanks in advance.

0 Answers
Related