Azure AI Speech (Cognitive Services)
Azure AI Speech is Azure's Cognitive Services text-to-speech API, separate from Azure OpenAI. It provides high-quality neural voices with broader language support and advanced speech customization.
When to use this vs Azure OpenAI TTS:
- Azure AI Speech - More languages, neural voices, SSML support, speech customization
- Azure OpenAI TTS - OpenAI models, integrated with Azure OpenAI services
Overview
| Property | Details |
|---|---|
| Description | Azure AI Speech is Azure's Cognitive Services text-to-speech API, separate from Azure OpenAI. It provides high-quality neural voices with broader language support and advanced speech customization. |
| Provider Route on LiteLLM | azure/speech/ |
Quick Start
LiteLLM SDK
SDK Usage
from litellm import speech
from pathlib import Path
import os
os.environ["AZURE_TTS_API_KEY"] = "your-cognitive-services-key"
speech_file_path = Path(__file__).parent / "speech.mp3"
response = speech(
model="azure/speech/azure-tts",
voice="alloy",
input="Hello, this is Azure AI Speech",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
)
response.stream_to_file(speech_file_path)
LiteLLM Proxy
proxy_config.yaml
model_list:
- model_name: azure-speech
litellm_params:
model: azure/speech/azure-tts
api_base: https://eastus.tts.speech.microsoft.com
api_key: os.environ/AZURE_TTS_API_KEY
Setup
- Create an Azure Cognitive Services resource in the Azure Portal
- Get your API key from the resource
- Note your region (e.g.,
eastus,westus,westeurope) - Use the regional endpoint:
https://{region}.tts.speech.microsoft.com
Cost Tracking (Pricing)
LiteLLM automatically tracks costs for Azure AI Speech based on the number of characters processed.
Available Models
| Model | Voice Type | Cost per 1M Characters |
|---|---|---|
azure/speech/azure-tts | Neural | $15 |
azure/speech/azure-tts-hd | Neural HD | $30 |
How Costs are Calculated
Azure AI Speech charges based on the number of characters in your input text. LiteLLM automatically:
- Counts the number of characters in your
inputparameter - Calculates the cost based on the model pricing
- Returns the cost in the response object
View Request Cost
from litellm import speech
response = speech(
model="azure/speech/azure-tts",
voice="alloy",
input="Hello, this is a test message",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
)
# Access the calculated cost
cost = response._hidden_params.get("response_cost")
print(f"Request cost: ${cost}")
Verify Azure Pricing
To check the latest Azure AI Speech pricing:
- Visit the Azure Pricing Calculator
- Set Service to "AI Services"
- Set API to "Azure AI Speech"
- Select Text to Speech and your region
- View the current pricing per million characters
Note: Pricing may vary by region and Azure subscription type.