I am not being able to stop Keyword Recognition Service.

Anish Byanjankar 0 Reputation points
2023-07-06T09:56:57.7433333+00:00

Hello everyone,

I am using Azure Speech SDK and Azure Keyword Recognition.

While using the Keyword Recognition, I am using the method: recognize_once_async.

import azure.cognitiveservices.speech as speechsdk

keyword_model = speechsdk.KeywordRecognitionModel(model_path)
audio_config = speechsdk.AudioConfig(use_default_microphone=True)
configurationkeyword_recognizer = speechsdk.KeywordRecognizer(audio_config)

result_future = keyword_recognizer.recognize_once_async(keyword_model)

This keeps waiting for the keyword, to be spoken by the user.

However, if I try to terminate the program at this point of time, while it is waiting for the keyword, I am not being able to do that.

I have implemented the Keyboard Interrupt, but it still waits for the keyword, before program terminates.

I would like to know about a method to resolve this and terminate the program, while this recognizer is waiting for the keyword to be spoken.

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,865 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Azar 25,850 Reputation points MVP
    2023-07-06T19:47:03.98+00:00

    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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.