Speech Cognitive services Authentication error (401) even with correct subscription key

Pierre-Louis VENTRE 46 Reputation points
2021-02-23T18:14:25.14+00:00

Hi
I meet a problem for building a speech to text with Azure. I followed this tutorial

https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-speech-to-text?tabs=script%2Cbrowser%2Cwindowsinstall&pivots=programming-language-python

And nothing is possible with my speech config. I set it as following :

speech_config = speechsdk.SpeechConfig(subscription="{<!-- -->{MY SUBSCRIPTION KEY}}", region="westus")  
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)  

I tried to re generate key many times, there is nothing to do I always get the error :

Speech Recognition canceled: CancellationReason.Error    
Error details: WebSocket upgrade failed: Authentication error (401). Please check subscription information and region name.    

I read everywhere that I certainly have a mistake in my key, or that my subscription is over, or I have reached the quota limit. But that's not the problem because I try with this method and get a success :

I followed advices of microsoft doc and tried this :

curl -v -X POST "https://YOUR_REGION.api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY" -H "Content-type: application/x-www-form-urlencoded" -H "Content-Length: 0"  

And it worked, I got a token with success
Then I tried :

curl -v -X POST "https://YOUR_REGION.stt.speech.microsoft.com/speech/recognition/interactive/cognitiveservices/v1?language=en-US" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Transfer-Encoding: chunked" -H "Content-type: audio/wav; codec=audio/pcm; samplerate=16000" --data-binary @YOUR_AUDIO_FILE  

And I got in text my audio_file
So that's not a problem of subscription, my key is valid.
So if anyone could help me to resolve this "Authentication Error Please check subscription" problem it would be amazing because it's making me mad since 3 days

Thank's for reading

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,395 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,382 questions
{count} votes

Accepted answer
  1. YutongTie-MSFT 46,801 Reputation points
    2021-02-24T17:14:43.507+00:00

    Hello everyone,

    This works for me now. Please check my code sample and let me know if you still have issue.

    # Copyright (c) Microsoft. All rights reserved.  
    # Licensed under the MIT license. See LICENSE.md file in the project root for full license information.  
      
    # <code>  
    import  azure.cognitiveservices.speech as speechsdk  
      
    # Creates an instance of a speech config with specified subscription key and service region.  
    # Replace with your own subscription key and service region (e.g., "westus").  
    speech_config = speechsdk.SpeechConfig(subscription="1fac40698f86************", region="westus")  
      
    # Creates a recognizer with the given settings  
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)  
    speech_config.set_property(speechsdk.PropertyId.Speech_LogFilename, "LogfilePathAndName")  
      
    print("Say something...please")  
      
      
    # Starts speech recognition, and returns after a single utterance is recognized. The end of a  
    # single utterance is determined by listening for silence at the end or until a maximum of 15  
    # seconds of audio is processed.  The task returns the recognition text as result.   
    # Note: Since recognize_once() returns only a single utterance, it is suitable only for single  
    # shot recognition like command or query.   
    # For long-running multi-utterance recognition, use start_continuous_recognition() instead.  
    result = speech_recognizer.recognize_once()  
      
    # Checks result.  
    if result.reason == speechsdk.ResultReason.RecognizedSpeech:  
        print("Recognized: {}".format(result.text))  
    elif result.reason == speechsdk.ResultReason.NoMatch:  
        print("No speech could be recognized: {}".format(result.no_match_details))  
    elif result.reason == speechsdk.ResultReason.Canceled:  
        cancellation_details = result.cancellation_details  
        print("Speech Recognition canceled: {}".format(cancellation_details.reason))  
        if cancellation_details.reason == speechsdk.CancellationReason.Error:  
            print("Error details: {}".format(cancellation_details.error_details))  
    # </code>  
    

    71721-image.png

    Regards,
    Yutong

    1 person found this answer helpful.

13 additional answers

Sort by: Most helpful
  1. Barthelemy Robert - Contractor 0 Reputation points
    2024-01-19T09:25:14.0833333+00:00

    Hello, I have the same issue since yesterday. My setup was working fine for a few month before. I think there is a new issue on the Microsoft side.