'How to get a list of available voices for Azure Text To Speech?

Is there a way to programatically list the available voices in Azure Text To Speech?

I've searched extensively and found this page https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support

But I have not found any way to get this information programatically - is it possible?



Solution 1:[1]

There is voices/list endpoint and it is documented here.

Example from the documentation:

GET /cognitiveservices/voices/list HTTP/1.1

Host: westus.tts.speech.microsoft.com
Authorization: Bearer [Base64 access_token]

Solution 2:[2]

Since 1.16.0 there is...

SpeechSynthesizer.GetVoicesAsync(string locale)

var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");            
using var synthesizer = new SpeechSynthesizer(config, null as AudioConfig);
using var result = await synthesizer.GetVoicesAsync();
if (result.Reason == ResultReason.VoicesListRetrieved)
{
    Debug.WriteLine($"Found {result.Voices.Count} voices");
}

There is a working example SynthesisGetAvailableVoicesAsync() method in the Azure-Samples github respository... there is a direct link to the Text-to-Speech samples at the top of the Text-to-speech quickstart page.

Solution 3:[3]

As per the documentation mentioned in the swagger, you could use the

api/languagegeneration/v2.0/Endpoints/locales

end point to get the supported locales.

/api/texttospeech/v2.0/datasets/locales

Solution 4:[4]

With python SDK, you can get the list of available voices via get_voices_async method on SpeechSynthesizer class.

get_voices_async method (see docs) returns a future ResultFuture (see docs) that you can await by calling get method on it.

In this case, the get method returns SynthesisVoicesResult object (see docs)

You can retrieve list of available voices from voices property in SynthesisVoicesResult object, which is a list of VoiceInfo object (see docs).

import azure.cognitiveservices.speech as speechsdk

# config
speech_config = speechsdk.SpeechConfig(subscription=<your_api_key>, region=<your_region>)

# Create your client
client = speechsdk.SpeechSynthesizer(speech_config=speech_config)

# Request the list of available voices
voices_result = client.get_voices_async().get()

# iterate through the list of voices
print([v.local_name for v in result.voices])

Similar api calls exist with the other language SDKs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ram?nas
Solution 2
Solution 3 Sajeetharan
Solution 4 Jerboas86