Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
966 views
in Technique[技术] by (71.8m points)

api - Azure Cognitive services - TTS

I got an api keys for Azure Cognitive services, but I can't find any documentation how I am calling this service through postmen. Anybody has experience with this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Seems you are trying to call Text To Speech service with your keys. There are two steps for that.

1. Need Access Token

You have to get your token like this format:

Request URL: https://YourResourceEndpoint/sts/v1.0/issuetoken
Method: POST
Hearder: Content-Type:application/x-www-form-urlencoded
Ocp-Apim-Subscription-Key:YourKeys

See The Screen shot for clarity:

enter image description here

Code Snippet:

public async Task<string> GetSpeechServiceToken()
        {
            try
            {
                string tokenUrl = $"https://YourServiceURL.cognitiveservices.azure.com/sts/v1.0/issuetoken";
                var tokenRequest = new HttpRequestMessage(HttpMethod.Post, tokenUrl);
                tokenRequest.Headers.Add("Ocp-Apim-Subscription-Key", "subscriptionKey");
                using (var client = new HttpClient())
                {
                    var tokenResponse = await client.SendAsync(tokenRequest);

                    var token = await tokenResponse.Content.ReadAsStringAsync();

                    return token;
                }

            }
            catch (Exception ex)
            {

                ex.Message.ToString();
            }
            return null;

        }

You could have a look on official Docs

2. Get List Of Voices With Token You Have Received Earlier

You can request for Text To Speech voice list Like below:

Request URL: https://centralus.tts.speech.microsoft.com/cognitiveservices/voices/list
Method : GET
Authorization: Bearer Token Paste Your Token Here

See the screen shot for clarity

enter image description here

You could find more details here

Note: In case of your test account You can create here

enter image description here

Update:

I would sent a request and somehow I got an uri or something where I can hear it? is this possible?

Yeah its possible. But in that case you have to use sdk. Here Is the complete sample.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...