2
votes

I'm trying to use the Azure Cognitive Services text-to-speech API, but no matter what I try, I get a 401 Unauthorized response.

I've created a Cognitive Services resource on my subscription in the West Europe region. Type is All Cognitive Services, status is active. I downloaded the CSharp sample from https://github.com/Azure-Samples/Cognitive-Speech-TTS and entered the West Europe URLs and my Cognitive Services subscription key into the code. When I run the sample, the access token is retrieved just fine, but the text-to-speech request returns 401.

Token URL: https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken

Service URL: https://westeurope.tts.speech.microsoft.com/cognitiveservices/v1

I've checked that the URLs are correct, I'm using the same region in both and the same one as the created resource. I went throught the troubleshooting page (https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/troubleshooting) and got the same 401 issue. I tried running the TTS request from Postman. I've tried both Key1 and Key2 from the Azure portal, and tried to regenerate a key. I've tried running the request also in Azure Functions, both locally and in the cloud.

I've decoded the access token and it seems like it has pretty much the right stuff in it, as far as I can tell. The only weird thing is, the exp field is a string and not a number (incorrect for a JWT). Could that be a bug in the auth system that is causing this error or am I doing something wrong?

Request

POST https://westeurope.tts.speech.microsoft.com/cognitiveservices/v1 HTTP/1.1
Authorization: Bearer <access-token>
User-Agent: TestApi
X-Microsoft-OutputFormat: audio-16khz-64kbitrate-mono-mp3
Content-Type: application/ssml+xml
Host: westeurope.tts.speech.microsoft.com
Content-Length: 209

<speak version="1.0" xml:lang="fi-FI">
  <voice name="Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)" xml:lang="fi-FI">Hei, muistathan suorittaa päivän harjoitteet ajoissa.</voice>
</speak>

Response

HTTP/1.1 401 Unauthorized
X-MSEdge-Ref: Ref A: AD369D30DDB7466B8A77086554F9DC46 Ref B: HEL02EDGE0112 Ref C: 2018-12-10T13:03:43Z
Date: Mon, 10 Dec 2018 13:03:42 GMT
Content-Length: 0
1
I gave a try to the CSharp sample here github.com/Azure-Samples/Cognitive-Speech-TTS/tree/master/… , with my West Europe Speech key and just changing westus to westeurope in both issueToken and v1 url, it's working on my side. Will be difficult to help more..Nicolas R

1 Answers

6
votes

To use the text-to-speech service, you have to have a Speech Service resource, instead of a Cognitive Services resource.

What makes that a bit unclear is that there's no specific mention in the documentation to make that distinction. A Cognitive Services resource will display a type value All Cognitive Services, which one would assume contains also the speech functionality. And when you specifically create a Speech Service resource, it's still listed as a Cognitive Services resource.