You are on page 1of 9

unit CommandAndControlU; //Uses SAPI 5.

1 early bound Automation interface uses ActiveX, {$ifdef CONDITIONALEXPRESSIONS} Variants, {$endif} Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, OleServer, SpeechLib_TLB, MMSystem, ExtCtrls, sLabel, sGroupBox, sPanel, sSkinManager; type TfrmCommandAndControl = class(TForm) sPanel1: TsPanel; Label3: TLabel; Label4: TLabel; Label5: TLabel; lstProgress: TListBox; GroupBox1: TGroupBox; lblMinVU: TLabel; lblMaxVU: TLabel; lblVU: TLabel; ProgressBar: TProgressBar; sSkinManager1: TsSkinManager; sLabel4: TsLabel; SpSharedRecoContext1: TSpSharedRecoContext; Image1: TImage; Shape1: TShape; Shape3: TShape; Shape2: TShape; sGroupBox1: TsGroupBox; sPanel2: TsPanel; sLabel5: TsLabel; sLabel1: TsLabel; sLabel2: TsLabel; sLabel3: TsLabel; Timer1: TTimer; Timer2: TTimer; Label1: TLabel; Timer3: TTimer; Label2: TLabel; Timer4: TTimer; Timer5: TTimer; Timer6: TTimer; Label6: TLabel; procedure FormCreate(Sender: TObject); procedure SpSharedRecoContext1AudioLevel(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; AudioLevel: Integer); procedure SpSharedRecoContext1Recognition(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: TOleEnum; const Result: ISpeechRecoResult); procedure SpSharedRecoContext1SoundEnd(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant); procedure SpSharedRecoContext1SoundStart(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant);

procedure Timer2Timer(Sender: TObject); procedure Timer3Timer(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Timer4Timer(Sender: TObject); procedure Timer5Timer(Sender: TObject); procedure Timer6Timer(Sender: TObject); procedure sPanel2Click(Sender: TObject); procedure sGroupBox1Click(Sender: TObject); procedure Label5Click(Sender: TObject); procedure sPanel1Click(Sender: TObject); private SRGrammar: ISpeechRecoGrammar; procedure InvokeUI(const TypeOfUI, Caption: WideString); public procedure Log(const Msg: String); overload; procedure Log(const Msg: String; const Args: array of const); overload; end; var //deklarasi global variabel frmCommandAndControl: TfrmCommandAndControl; x:integer=-1; tmp: byte; implementation {$R *.dfm} uses SAPI, ComObj; { TfrmVoiceDictationAPI } //BACA PORT function PortIn(Port:Word):Byte;stdcall;external'io.dll'; //TULIS PORT procedure PortOut(Port:Word;Data:Byte);stdcall;external'io.dll'; procedure TfrmCommandAndControl.Log(const Msg: String); //buat enable log kalau di disable akan mempercepat proses recognition begin if not Assigned(lstProgress) then Exit; lstProgress.Items.Add(Msg); lstProgress.ItemIndex := lstProgress.Items.Count - 1 end; procedure TfrmCommandAndControl.Log(const Msg: String; const Args: array of cons t); //buat nambah format log begin //Log(Format(Msg, Args)) end; procedure TfrmCommandAndControl.FormCreate(Sender: TObject); i ini juga buat nge load gramarnya begin timer1.enabled:=False; timer2.Enabled:=false; timer3.Enabled:=false; //inti aplikas

timer4.Enabled:=false; timer5.Enabled:=false; timer6.Enabled:=false; //portout ($378, tmp or $1); portout ($378, tmp and $fe); //default lampunya mati //OnAudioLevel event is not fired by default - this changes that SpSharedRecoContext1.EventInterests := SREAllEvents; SRGrammar := SpSharedRecoContext1.CreateGrammar(0); SRGrammar.CmdLoadFromFile('kamus.xml', SLODynamic); SRGrammar.CmdSetRuleIdState(0, SGDSActive) end; function GetProp(Props: ISpeechPhraseProperties; alue gramar const Name: String): ISpeechPhraseProperty; overload; var I: Integer; Prop: ISpeechPhraseProperty; begin Result := nil; for I := 0 to Props.Count - 1 do begin Prop := Props.Item(I); if CompareText(Prop.Name, Name) = 0 then begin Result := Prop; Break end end end; //buat baca nilai/v

function GetPropValue(SRResult: ISpeechRecoResult; //sama buat baca nilai/value gramar juga const Path: array of String): OleVariant; var Prop: ISpeechPhraseProperty; PathLoop: Integer; begin for PathLoop := Low(Path) to High(Path) do begin if PathLoop = Low(Path) then //top level property Prop := GetProp(SRResult.PhraseInfo.Properties, Path[PathLoop]) else //nested property Prop := GetProp(Prop.Children, Path[PathLoop]); if not Assigned(Prop) then begin Result := Unassigned; Exit; end end; Result := Prop.Value end; procedure TfrmCommandAndControl.Timer6Timer(Sender: TObject); //nutup pintu sepe da/cycle begin x:=x+1; tmp:=PortIn($378);

if x=0 then begin portout ($378, tmp or $10); end; if x=1 then begin portout ($378, tmp and $ef); end; if x=15 then begin x:=-1; end; end; procedure TfrmCommandAndControl.Timer5Timer(Sender: TObject);//buka pintu motor/ cycle selama 15 detik begin x:=x+1; tmp:=PortIn($378); if x=0 then begin portout ($378, tmp or $4); end; if x=1 then begin portout ($378, tmp and $fb); end; if x=15 then begin x:=-1; end; end; procedure TfrmCommandAndControl.InvokeUI(const TypeOfUI, Caption: WideString); //ga tahu buat apaan? var U: OleVariant; begin U := Unassigned; if SpSharedRecoContext1.Recognizer.IsUISupported(TypeOfUI, U) then SpSharedRecoContext1.Recognizer.DisplayUI(Handle, Caption, TypeOfUI, U) end;

procedure TfrmCommandAndControl.SpSharedRecoContext1AudioLevel( //munculin ker as kecilnya suara di Voice unit ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; AudioLevel: Integer); begin ProgressBar.Position := AudioLevel; lblVU.Caption := IntToStr(AudioLevel) end; procedure TfrmCommandAndControl.SpSharedRecoContext1Recognition( //nilai dari gramar ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: TOleEnum; const Result: ISpeechRecoResult); begin with Result.PhraseInfo do begin //Log('OnRecognition: %s', [GetText(0, -1, True)]); //buat log jadi di disa ble aja case GetPropValue(Result, ['chosencolour', 'colourvalue']) of 1: begin sLabel1.Caption:='open car'; sLabel5.Caption:='pagar mobil terbuka'; Shape1.Brush.Color:= cllime; timer1.enabled := true; timer2.Enabled:=False; timer3.Enabled:=true; timer4.Enabled:=false; timer5.Enabled:=False; timer6.Enabled:=False; end; 2: begin sLabel1.Caption:='close car'; sLabel5.Caption:='pagar mobil tertutup'; Shape1.Brush.Color:= clBlack; timer1.enabled := False; timer2.Enabled:=True; timer3.Enabled:=true; timer4.Enabled:=false; timer5.Enabled:=False; timer6.Enabled:=False; end; 3: begin //portout ($378, tmp and $fe); portout ($378, tmp or $1); //hidupkan lampu sLabel1.Caption:='On Lamp'; sLabel5.Caption:='lampu taman hidup'; Shape2.Brush.Color:= clLime; end; 4: begin sLabel1.Caption:='off lamp'; sLabel5.Caption:='lampu taman mati';

Shape2.Brush.Color:= clBlack; //portout ($378, tmp or $1); portout ($378, tmp and $fe); // matikan lampu end; 5: begin sLabel1.Caption:='open cycle'; sLabel5.Caption:='pagar motor terbuka'; Shape3.Brush.Color:= clLime; timer1.enabled:= False; timer2.Enabled:=false; timer3.Enabled:=false; timer4.Enabled:=true; timer5.Enabled:=true; timer6.Enabled:=false; end; 6: begin sLabel1.Caption:='close cycle'; sLabel5.Caption:='pagar motor tertutup'; Shape3.Brush.Color:= clBlack; timer1.enabled:=False; timer2.Enabled:=false; timer3.Enabled:=false; timer4.Enabled:=true; timer5.Enabled:=false; timer6.Enabled:=true; end; {7: begin sLabel1.Caption:=''; sLabel5.Caption:=''; Shape1.Brush.Color:=clblack; Shape2.Brush.Color:=clblack; Shape3.Brush.Color:=clBlack; timer1.enabled:=False; timer2.Enabled:=false; timer3.Enabled:=false; timer4.Enabled:=false; timer5.Enabled:=false; timer6.Enabled:=false; portout ($378, tmp or $1); end; } 8: begin Application.Terminate; end; 9: begin Label5.Visible:=Enabled; end; end; end; end;

procedure TfrmCommandAndControl.SpSharedRecoContext1SoundEnd( //buat muncul in log sound end ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant); begin Log('OnSoundEnd') end; procedure TfrmCommandAndControl.SpSharedRecoContext1SoundStart( //buat muncu lin log sound start ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant); begin Log('OnSoundStart') end; procedure TfrmCommandAndControl.Timer2Timer(Sender: TObject);//buat buka pintu m obil begin x:=x+1; tmp:=PortIn($378); if x=0 then begin portout ($378, tmp or $10); end; if x=1 then begin portout ($378, tmp and $ef); end; if x=15 then begin x:=-1; end; end; procedure TfrmCommandAndControl.Timer3Timer(Sender: TObject);//timer countdown 1 0 detik begin label1.Caption:=inttostr(strtoint(label1.Caption)-1); if strtoint(label1.Caption)=0 then begin timer1.enabled:=False; timer2.Enabled:=false; timer3.Enabled:=false; timer4.Enabled:=false; timer5.Enabled:=false; timer6.Enabled:=false; Label1.Caption:='10';

end; end; procedure TfrmCommandAndControl.Timer1Timer(Sender: TObject);//tutup pintu mobil begin x:=x+1; tmp:=PortIn($378); if x=0 then begin portout ($378, tmp or $4); end; if x=1 then begin portout ($378, tmp and $fb); end; if x=15 then begin x:=-1; end; end; procedure TfrmCommandAndControl.Timer4Timer(Sender: TObject);//timer countdown 7 detik begin label2.Caption:=inttostr(strtoint(label2.Caption)-1); if strtoint(label2.Caption)=0 then begin timer1.enabled:=False; timer2.Enabled:=false; timer3.Enabled:=false; timer4.Enabled:=false; timer5.Enabled:=false; timer6.Enabled:=false; Label2.Caption:='7'; end; end; procedure TfrmCommandAndControl.sPanel2Click(Sender: TObject); begin end; procedure TfrmCommandAndControl.sGroupBox1Click(Sender: TObject); begin end; procedure TfrmCommandAndControl.Label5Click(Sender: TObject); begin

end; procedure TfrmCommandAndControl.sPanel1Click(Sender: TObject); begin end; end.

You might also like