WebSocket upgrade failed: Authentication error (401). Please check subscription information and region name.

Helen Mamalaki 5 Reputation points
2024-10-03T15:08:32.0233333+00:00

Hi,

I'm following these MS Learn docs on Microsoft Entra authentication with the Speech SDK

I am successfully getting back a token issued to me which I pass onto the SpeechConfig object as per the docs but then SpeechRecogniser immediately errors out with:

"WebSocket upgrade failed: Authentication error (401). Please check subscription information and region name. "

I an on the S0 standard pricing tier.

I have given myself 'Speech Services Speech User' and 'Contributor' role on the Speech Services instance.

Region is 'uksouth' and I have a custom domain name for the endpoint all as per the docs. Is there anything else I need to do that I'm missing?

 private async Task CreateContinuousRecognizer(TextAreaObject textAreaObject)
 {
     string region = "uksouth";
     var authorizationToken = await ResourceToken();
     SpeechConfig sc = SpeechConfig.FromAuthorizationToken(authorizationToken, region);
     AudioConfig ac = AudioConfig.FromDefaultMicrophoneInput();
     SpeechRecognizer sr = new SpeechRecognizer(sc, ac);
     _original = textAreaObject.Text;
     StringBuilder sb = new();
     success = true;
     AppendNewLines(_original);
     sr.Recognizing += Recognizing;
     sr.Recognized += Recognized;
     sr.Canceled += Canceled; 
 }

    private async Task<string> ResourceToken()
    {
        string resourceId = "<our resource id>";
        string[] scopes = { "https://cognitiveservices.azure.com/.default", };
        TokenRequestContext context = new(scopes);
        InteractiveBrowserCredential cred = new();
        string aadToken = (await cred.GetTokenAsync(context)).Token;
        string token = $"aad#{resourceId}#{aadToken}";
        return token;
    }
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,765 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 52,596 Reputation points
    2024-10-04T00:08:54.4366667+00:00

    Hello Helen,

    Thanks for reaching out to us, for Microsoft Entra authentication with Speech resources, you need to assign either the Cognitive Services Speech Contributor or Cognitive Services Speech User role.

    Please kindly have a try and let us know if it helps.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.

    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.