@
DelphiCan
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Effects,
FMX.Ani, FMX.StdCtrls, FMX.Layouts, FMX.ListBox, FMX.Objects,
FMX.Controls.Presentation,android.speech
{$IFDEF ANDROID}
,Androidapi.JNI.Net
,Androidapi.JNI.GraphicsContentViewText
,Androidapi.JNI.JavaTypes
,Androidapi.JNI.App
,FMX.Platform.Android
,FMX.Helpers.Android
,Androidapi.Helpers
,Androidapi.JNIBridge
,Androidapi.JNI.Os, FMX.Edit
{$ENDIF};
type
TForm1 = class(TForm)
voicepanel: TRectangle;
Label1: TLabel;
Layout1: TLayout;
Label2: TLabel;
ListBox1: TListBox;
Layout2: TLayout;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
FloatAnimation1: TFloatAnimation;
ShadowEffect1: TShadowEffect;
Image2: TImage;
karanlik: TRectangle;
Edit1: TEdit;
Button1: TButton;
Image7: TImage;
procedure Button1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FloatAnimation1Finish(Sender: TObject);
private
procedure ShowPopup;
procedure HidePopup;
procedure sesliarama;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
function ErrorMessage(Error: Integer): string;
begin
case Error of
TJSpeechRecognizer_ERROR_AUDIO: Result := 'Ses kayıt hatası';
TJSpeechRecognizer_ERROR_CLIENT: Result := 'Diğer istemci tarafı hatalar';
TJSpeechRecognizer_ERROR_INSUFFICIENT_PERMISSIONS: Result := 'Yetersiz izinler';
TJSpeechRecognizer_ERROR_NETWORK: Result := 'Diğer Ağ ile ilgili hatalar';
TJSpeechRecognizer_ERROR_NETWORK_TIMEOUT: Result := 'Ağ işlemi zaman aşımına uğradı';
TJSpeechRecognizer_ERROR_NO_MATCH: Result := 'Hiçbir tanıma sonucu eşleşti';
TJSpeechRecognizer_ERROR_RECOGNIZER_BUSY: Result := 'Tanıma Hizmet meşgul';
TJSpeechRecognizer_ERROR_SERVER: Result := 'Sunucu hatası durumu';
TJSpeechRecognizer_ERROR_SPEECH_TIMEOUT: Result := 'Herhangi bir konuşma girişi Bulunamadı';
else Result := 'Tanımlanamaya Hata ' + IntToStr(Error);
end;
end;
type
TRecognitionListener = class(TJavaLocal, JRecognitionListener)
procedure onBeginningOfSpeech; cdecl;
procedure onBufferReceived(Buffer: TJavaArray<Byte>); cdecl;
procedure onEndOfSpeech; cdecl;
procedure onError(Error: Integer); cdecl;
procedure onEvent(EventType: Integer; Params: JBundle); cdecl;
procedure onPartialResults(PartialResults: JBundle); cdecl;
procedure onReadyForSpeech(Params: JBundle); cdecl;
procedure onResults(Results: JBundle); cdecl;
procedure onRmsChanged(RmsdB: Single); cdecl;
end;
procedure TRecognitionListener.onBeginningOfSpeech;
begin
Form1.label2.text := 'Konuşma Başladı';
end;
procedure TRecognitionListener.onBufferReceived(Buffer: TJavaArray<Byte>);
begin
end;
procedure TRecognitionListener.onEndOfSpeech;
begin
Form1.label2.text := 'Konuşma Bitti';
end;
procedure TRecognitionListener.onError(Error: Integer);
begin
Form1.label2.text:='Hata: ' + ErrorMessage(Error);
end;
procedure TRecognitionListener.onEvent(EventType: Integer; Params: JBundle);
begin
end;
procedure TRecognitionListener.onPartialResults(PartialResults: JBundle);
begin
end;
procedure TRecognitionListener.onReadyForSpeech(Params: JBundle);
begin
Form1.label2.text:='Konuçma İçin Hazır';
end;
procedure TRecognitionListener.onResults(Results: JBundle);
var
ArrayList: JArrayList;
I: Integer;
Text: string;
begin
Text := '';
ArrayList := Results.getStringArrayList(StringToJString(TJSpeechRecognizer_RESULTS_RECOGNITION));
Form1.Listbox1.Clear;
for I := 0 to ArrayList.size - 1 do
Form1.Listbox1.Items.Add(JStringToString(ArrayList.get(I).toString));
Form1.label2.text:='Sonuçlar';
Form1.Edit1.SetFocus;
end;
procedure TRecognitionListener.onRmsChanged(RmsdB: Single);
begin
end;
var
SpeechRecognizer: JSpeechRecognizer;
RecognitionListener: JRecognitionListener;
procedure Tform1.sesliarama;
begin
Edit1.Text:='';
label2.text:='';
Listbox1.Clear;
if not TJSpeechRecognizer.JavaClass.isRecognitionAvailable(SharedActivityContext) then
begin
ShowMessage('Konuşma tanıma mevcut değil');
Exit;
end;
CallInUiThread(
procedure
begin
if SpeechRecognizer = nil then
begin
SpeechRecognizer := TJSpeechRecognizer.JavaClass.createSpeechRecognizer(SharedActivityContext);
RecognitionListener := TRecognitionListener.Create;
SpeechRecognizer.setRecognitionListener(RecognitionListener);
end;
SpeechRecognizer.startListening(TJRecognizerIntent.JavaClass.getVoiceDetailsIntent(SharedActivityContext));
end);
ShowPopup;
end;
procedure TForm1.ShowPopup;
begin
FloatAnimation1.StartValue:= -voicepanel.Height;
FloatAnimation1.StopValue:= (self.Height / 1.5)-(voicepanel.Height-2);
voicepanel.Visible:=true;
karanlik.Visible:=true;
FloatAnimation1.Start;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Edit1.Text:=Listbox1.Selected.Text;
//if Edit1.text<>'' then cariarama; //arama yaptırılabilir
Edit1.SetFocus;
hidePopup;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
HidePopup;
end;
procedure TForm1.FloatAnimation1Finish(Sender: TObject);
begin
if FloatAnimation1.StartValue <> 0-voicepanel.Height then
begin
voicepanel.Visible:=false;
karanlik.Visible:=false;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
HidePopup;
end;
procedure TForm1.HidePopup;
begin
FloatAnimation1.StartValue:= (self.Height / 2)-(voicepanel.Height-2);
FloatAnimation1.StopValue:= 0-voicepanel.Height;
FloatAnimation1.Start;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sesliarama;
end;
end.