I've got the Android speech recognition stuff working well but have a question.
I've got a method called StartListening(). It's starts the speech recognition mechanism and when the OnResult call back gets fired the caller is notified via an event notification.
Now, what I'd like is a method call Listen. It should return a string consisting of the words spoken by the user. The best I've been able to come with is:
async public Task<string> Listen()
{
Words = null;
GlobalVariables.SpokenWords.SpokenWordsEvent += SpokenWordsEventHandler;
Device.BeginInvokeOnMainThread(() =>
{
StartListening();
});
while (Words == null)
await Task.Delay(100);
GlobalVariables.SpokenWords.SpokenWordsEvent -= SpokenWordsEventHandler;
return (Words);
}
It does work but is very ugly. I'm sure there's a better way but I don't see it...any help? It would be ideal if it was not marked async...