Fabian1648 2 Posted August 8, 2022 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
Dave Nottage 563 Posted August 8, 2022 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; 1 Share this post Link to post
Fabian1648 2 Posted August 9, 2022 (edited) 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 August 9, 2022 by Fabian1648 Share this post Link to post