Forum Xamarin.Android

How to use Callback and EventListener in C#

S_Olias_SS_Olias_S DEMember ✭✭


I`m trying to use the Microsoft Cognitive Service sdk on Android.
I already made a Binding Library of the current aar.

// Create a SpeechRecognizer
SpeechRecognizer reco = new SpeechRecognizer(getSpeechConfig(), getAudioConfig());

    var task = reco.RecognizeOnceAsync();

            // Note: this will block the UI thread, so eventually, you want to
            //        register for the event (see full samples)
            SpeechRecognitionResult result = (SpeechRecognitionResult)task.Get();

Now i want to use it without Blocking the Ui thread and to get intermediate results, so i found the following example: Devices SDK Starter App/
But Unfortunately it is in Java:

   // Set callback for intermediate results
reco.recognizing.addEventListener((o, speechRecognitionResultEventArgs) -> {
                final String s = speechRecognitionResultEventArgs.getResult().getText();
                Log.i(logTag, "Intermediate result received: " + s);
                // your code goes here
                // ...


// Set a callback for recognizer returned
setOnTaskCompletedListener(task, result -> {
final String s = result.getText();
Log.i(logTag, "Recognizer returned: " + s);
// your code goes here
// ...


How can i transform this Java Code in c# Code?
How can i use the eventListener or can i accomplish the task another way?

Best Answer


Sign In or Register to comment.