1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SpeechLib_TLB, StdCtrls;
const SP_GETWHOLEPHRASE = -1;
type
TForm3 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private-Deklarationen }
public
SpSharedRecoContext1: TSpSharedRecoContext;
MyGrammar : 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);
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SpSharedRecoContext1.Free;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
SpSharedRecoContext1 := TSpSharedRecoContext.Create(self);
SpSharedRecoContext1.OnRecognition := SpSharedRecoContext1Recognition;
SpSharedRecoContext1.OnHypothesis := SpSharedRecoContext1Hypothesis;
MyGrammar := SpSharedRecoContext1.CreateGrammar(0);
MyGrammar.DictationSetState(SGDSActive);
end;
procedure TForm3.SpSharedRecoContext1Recognition(ASender: TObject;
StreamNumber: Integer;
StreamPosition: OleVariant;
RecognitionType: SpeechRecognitionType;
const Result: ISpeechRecoResult);
begin
Caption := '';
Memo1.Lines.Add(Result.PhraseInfo.GetText(SP_GETWHOLEPHRASE,SP_GETWHOLEPHRASE,true));
end;
procedure TForm3.SpSharedRecoContext1Hypothesis(ASender: TObject;
StreamNumber: Integer;
StreamPosition: OleVariant;
const Result: ISpeechRecoResult);
begin
Caption := 'I am listening...';
end;
end. |
Partager