public static int Init() { // Create a queue to receive completed speech to text results MessageQueue = new ConcurrentQueue <QueueItem>(); // Configure the recognizer. This requires you to have an active Azure Speech to Text service subscription: // https://azure.microsoft.com/en-gb/services/cognitive-services/speech-to-text var config = SpeechConfig.FromSubscription("YOUR_SUBSCRIPTION_KEY", "YOUR_SUBSCRIPTION_REGION"); Recognizer = new SpeechRecognizer(config); // Add a callback to receive recognized text, and queue it up for a Lua callback called "onSpeech", which should be registered by the caller in Lua Recognizer.Recognized += (s, e) => { if (e.Result.Reason == ResultReason.RecognizedSpeech) { Console.WriteLine("Recognized: " + e.Result.Text); MessageQueue.Enqueue(new QueueItem { Callback = "onSpeech", Param = e.Result.Text }); } }; EventHandler <RecognitionEventArgs> MakeEventFunc(string name) => (object s, RecognitionEventArgs e) => MessageQueue.Enqueue(new QueueItem { Callback = name }); // Register some Lua callbacks for the other events we get from the recognizer Recognizer.SessionStarted += (s, e) => MakeEventFunc("onSpeechSessionStarted"); Recognizer.SessionStopped += (s, e) => MakeEventFunc("onSpeechSessionStopped"); Recognizer.SpeechStartDetected += (s, e) => MakeEventFunc("onSpeechStartDetected"); Recognizer.SpeechEndDetected += (s, e) => MakeEventFunc("onSpeechEndDetected"); // Register our Lua function to enable listening StartListeningDelegate = new FFI.FFIFunction(OnStartListening); FFI.RegisterGlobalFunction("StartListening", StartListeningDelegate, 0, IntPtr.Zero); // Register our Lua function to stop listening StopListeningDelegate = new FFI.FFIFunction(OnStopListening); FFI.RegisterGlobalFunction("StopListening", StopListeningDelegate, 0, IntPtr.Zero); // Register our update function for queue processing UpdateDelegate = new Observer.UpdateFunction(Update); Observer.AddCallbackUpdate(UpdateDelegate, IntPtr.Zero); // zero is init success return(0); }