How to use Callback and EventListener in C#

Hey,

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:
https://github.com/Azure-Samples/Cognitive-Services-Speech-Devices-SDK/blob/master/Samples/Android/Speech Devices SDK Starter App/Sample_Code_Walkthrough.md
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();
reco.close();
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

Answers

Sign In or Register to comment.