Hi Anish
To terminate the program while the KeywordRecognizer is waiting for the keyword to be spoken using the Azure Speech SDK, you can try the following approach:
Implement a timeout mechanism:
require "azure_cognitiveservices_speech" keyword_model = Azure::CognitiveServices::Speech::KeywordRecognitionModel.from_file(model_path) audio_config = Azure::CognitiveServices::Speech::AudioConfig.from_default_microphone_input keyword_recognizer = Azure::CognitiveServices::Speech::KeywordRecognizer.new(audio_config) result_future = keyword_recognizer.recognize_once_async(keyword_model) # Wait for a certain duration (e.g., 5 seconds) before terminating the program timeout_duration = 5 timeout = Time.now + timeout_duration while !result_future.complete? && Time.now < timeout # Perform any other necessary operations within the loop end if result_future.complete? result = result_future.get # Process the result if needed end # Terminate the program here
In the code above, the loop waits until either the result is complete or the timeout duration is reached. If the timeout is reached and the result is not complete, the program proceeds with termination.
hope this helps