DelphiWorlds / Kastri

Cross-platform library for Delphi
MIT License
499 stars 119 forks source link

[VoiceRecognition] Wait for finish of recording #53

Closed michelinok closed 3 years ago

michelinok commented 3 years ago

Since i've not found a way to ask for help, i'll try here (it's not a bug nor a feature request).

In my code I would like to wait for "FSpeech.StartRecording" to finish

I've tryed this:

FSpeech.StartRecording; while FSpeech.IsRecording do begin end;

But it doesn't wait...Any suggestion?

Many thanks!

DelphiWorlds commented 3 years ago

Possibly because IsRecording is not set immediately when StartRecording is called. What are you trying to do inside the loop? If you are not doing anything inside the loop, is there some reason you are unable to use the OnStopped event?

michelinok commented 3 years ago

I'm quite a newbie...I'm trying to play a file (this works, it plays mp3 of random words) then listen and check if the recognized text is ok. It's a sort of play-listen-check if equal. It would be great if i could do this inside a loop (changing the mp3 and the corresponding text to check).

DelphiWorlds commented 3 years ago

The recognized text is passed in the OnText event. Use the OnStopped event to know when recording has stopped.

michelinok commented 3 years ago

One more question...if no text is recognized, which event is fired?

DelphiWorlds commented 3 years ago

OnStopped is fired regardless of whether or not any text is recognized, so if you want to know whether no text was recognized, one way would be to have a flag you set before calling StartRecording, then change that flag in OnText. When OnStopped is called, you will know whether or not any text has been recognized by the state of that flag