Sign Up Form

Sign Up

Azure tts api about getting voice lists for azure text to speech ?

347 145 point-admin
  • 2

To get a list of available voices for Azure Text-to-Speech using JavaScript, you can make a call to the Azure Text-to-Speech API’s endpoint for listing voices.

Here is an example:

JavaScript :

const subscriptionKey = 'YOUR_SUBSCRIPTION_KEY';
const region = 'YOUR_REGION';

async function getVoicesList() {
const response = await fetch(`https://${region}.tts.speech.microsoft.com/cognitiveservices/voices/list`, {
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey
}
});

if (!response.ok) {
throw new Error('Error fetching voices list');
}

const voices = await response.json();
return voices;
}

getVoicesList()
.then(voices => console.log(voices))
.catch(error => console.error('Error:', error));
  1. Subscription Key and Region: Replace YOUR_SUBSCRIPTION_KEY and YOUR_REGION with your Azure subscription key and region.
  2. Fetch Request: The fetch API is used to make an HTTP GET request to the Azure Text-to-Speech voices list endpoint.
  3. Headers: The Ocp-Apim-Subscription-Key header is set to authenticate the request.
  4. Response Handling: The response is checked for success, then parsed as JSON to get the list of voices.

This will give you the list of available voices that you can use with Azure Text-to-Speech.

Leave a Reply

Your email address will not be published.