Jump to content
Sign in to follow this  
Fabian1648

[Android] App does not answer anymore

Recommended Posts

Hello,

I'm trying to use Google's voice recognition service in an Android app but my app loses control when retrieving data.

 

1° In the triggered event, it is not possible to process the provided answer (the app loses the hand and Android indicates the app does not answer anymore after several seconds)

procedure TForm1.SpeechRecognition1Recognition(Sender: TObject; Guess: string);
begin
 ... // Impossible to do something
end;

 

2° If I start a timer, the code in the timer works and the app does not lose control

procedure TForm1.SpeechRecognition1Recognition(Sender: TObject; Guess: string);
begin
 timer3.Enabled:=true;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin
 try
   ...
 finally
   timer3.Enabled:=false;
 end;
end;

 

3°  If I try to transmit the obtained answer through a global variable to be able to process it in the timer code, same behaviour of point 1 most of the time (it works sometimes...)

procedure TForm1.SpeechRecognition1Recognition(Sender: TObject; Guess: string);
begin
 G_Heard:=Guess;
 timer3.Enabled:=true;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin
 try
  ShowMessage('Start timer3: '+G_Heard);//DEBUG
 finally
  timer3.Enabled:=false;
 end;
end;

 

Does anyone have an explanation or solution to prevent the app from getting out of control?

 

Thank you in advance

Share this post


Link to post

You do not indicate what library you are using. Is it this one (or similar)? https://github.com/jimmckeeth/FireMonkey-Android-Voice

 

Where you have "impossible to do something", you do not indicate exactly what it is your code is doing. Nor do you show what it is doing in the timer handler. Given that code executes, it's quite possible that the SpeechRecognition1Recognition event is executing outside of the main thread, which may account for the other issues you are seeing. If that is the case, you could use a construct like this:

procedure TForm1.SpeechRecognition1Recognition(Sender: TObject; Guess: string);
begin
  TThread.Synchronize(nil, 
    procedure
    begin
      G_Heard := Guess;
      // Execute your other code, here
    end
  );
end;

 

  • Like 1

Share this post


Link to post

I found the source of the problem using Android Device Monitor. the permission "record sounds" was not enabled in the project parameters of the app!

 

In this case, Android's permissions management doesn't seem to work perfectly since the code was working sometimes.

Edited by Fabian1648

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×