Azure AI Speech
Azure AI Speech (Cognitive Services)
Azure AI Speech는 Azure OpenAI와는 별개의 Azure Cognitive Services 텍스트-음성 변환(TTS) API예요. 더 넓은 언어 지원과 고급 음성 커스터마이징을 갖춘 고품질 신경망 음성을 제공해요.
Azure OpenAI TTS와의 차이: Azure AI Speech는 언어와 신경망 음성, SSML 지원, 음성 커스터마이징이 더 풍부해요. 반면 Azure OpenAI TTS는 OpenAI 모델을 Azure OpenAI 서비스와 통합해요.
출처: 문서
본문
개요 (Overview)
| 속성 | 설명 |
|---|---|
| 설명 | Azure OpenAI와는 별개의 Azure Cognitive Services 텍스트-음성 변환 API. 고품질 신경망 음성, 넓은 언어 지원, 고급 음성 커스터마이징 제공 |
| LiteLLM 라우트 | azure/speech/ |
빠른 시작 (Quick Start)
LiteLLM SDK:
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 (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)
- Azure Portal에서 Azure Cognitive Services 리소스 생성하기
- 리소스에서 API 키 가져오기
- 지역(region) 기록하기 (예: eastus, westus, westeurope)
- 지역 엔드포인트 사용하기:
https://{region}.tts.speech.microsoft.com
비용 추적 (Cost Tracking)
LiteLLM은 처리한 문자 수를 기준으로 Azure AI Speech 비용을 자동 추적해요.
사용 가능한 모델
| 모델 | 음성 타입 | 백만 문자당 비용 |
|---|---|---|
azure/speech/azure-tts |
Neural | $15 |
azure/speech/azure-tts-hd |
Neural HD | $30 |
비용 계산 방식
Azure AI Speech는 입력 텍스트의 문자 수를 기준으로 요금을 부과해요. LiteLLM이 자동으로:
- 입력 파라미터의 문자 수를 세어요
- 모델 가격을 기준으로 비용을 계산해요
- 응답 객체에 비용을 담아 반환해요
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}")
Azure 가격 확인
최신 Azure AI Speech 가격은 Azure Pricing Calculator에서 "AI Services" → "Azure AI Speech" → Text to Speech와 지역을 선택해 확인할 수 있어요. 가격은 지역과 Azure 구독 유형에 따라 다를 수 있어요.
음성 매핑 (Voice Mapping)
LiteLLM은 OpenAI 음성 이름을 Azure 신경망 음성으로 자동 매핑해요.
| OpenAI 음성 | Azure 신경망 음성 | 설명 |
|---|---|---|
| alloy | en-US-JennyNeural | 중립적이고 균형 잡힘 |
| echo | en-US-GuyNeural | 따뜻하고 활기참 |
| fable | en-GB-RyanNeural | 표현력 있고 극적임 |
| onyx | en-US-DavisNeural | 깊고 권위 있음 |
| nova | en-US-AmberNeural | 친근하고 대화적 |
| shimmer | en-US-AriaNeural | 밝고 쾌활함 |
지원 파라미터 (Supported Parameters)
response = speech(
model="azure/speech/azure-tts",
voice="alloy", # Required: Voice selection
input="text to convert", # Required: Input text
speed=1.0, # Optional: 0.25 to 4.0 (default: 1.0)
response_format="mp3", # Optional: mp3, opus, wav, pcm
api_base="https://eastus.tts.speech.microsoft.com",
api_key="your-key",
)
응답 형식 (Response Formats)
| 형식 | Azure 출력 형식 | 샘플 레이트 |
|---|---|---|
| mp3 | audio-24khz-48kbitrate-mono-mp3 | 24kHz |
| opus | ogg-48khz-16bit-mono-opus | 48kHz |
| wav | riff-24khz-16bit-mono-pcm | 24kHz |
| pcm | raw-24khz-16bit-mono-pcm | 24kHz |
원시 SSML 전달 (Passing Raw SSML)
LiteLLM은 입력에 SSML이 포함되어 있는지(<speak> 태그 확인) 자동으로 감지해 변환 없이 Azure에 그대로 전달해요. 이렇게 하면 음성 합성을 완전히 제어할 수 있어요.
원시 SSML을 쓰는 경우:
- 다국어 음성과
<lang>요소로 텍스트 번역 (예: 영어 텍스트 → 스페인어 음성) - 여러 음성이나 prosody 변경이 있는 복잡한 SSML 구조
- 발음, 휴지, 강조 등 음성 기능의 세밀한 제어
from litellm import speech
# Use <lang> element to convert English text to Spanish speech
# The <lang> element forces the output language regardless of input text language
language_code = "es-ES"
text = "Hello, how are you today?" # English text
voice = "en-US-AvaMultilingualNeural"
ssml = f"""
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xml:lang="{language_code}">
<voice name="{voice}">
<lang xml:lang="{language_code}">{text}</lang>
</voice>
</speak>
"""
response = speech(
model="azure/speech/azure-tts",
voice=voice,
input=ssml, # LiteLLM auto-detects SSML and sends as-is
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
)
response.stream_to_file("speech.mp3")
Proxy로 SSML 전달:
curl http://0.0.0.0:4000/v1/audio/speech \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "azure-speech",
"voice": "en-US-AvaMultilingualNeural",
"input": "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xmlns:mstts=\"http://www.w3.org/2001/mstts\" xml:lang=\"es-ES\"><voice name=\"en-US-AvaMultilingualNeural\"><lang xml:lang=\"es-ES\">Hello, how are you today?</lang></voice></speak>"
}' \
--output speech.mp3
Azure 전용 파라미터 보내기
Azure AI Speech는 선택적 파라미터로 고급 SSML 기능을 지원해요:
style: 말하기 스타일 (예: "cheerful", "sad", "angry", "whispering")styledegree: 스타일 강도 (0.01 ~ 2)role: 음성 역할 (예: "Girl", "Boy", "SeniorFemale", "SeniorMale")lang: 다국어 음성용 언어 코드 (예: "es-ES", "fr-FR", "hi-IN")
사용자 지정 Azure 음성
from litellm import speech
response = speech(
model="azure/speech/azure-tts",
voice="en-US-AndrewNeural", # Use Azure voice directly
input="Hello, this is a test",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
response_format="mp3",
)
response.stream_to_file("speech.mp3")
말하기 스타일 (Speaking Style)
from litellm import speech
response = speech(
model="azure/speech/azure-tts",
voice="en-US-JennyNeural", # Must be a voice that supports styles
input="Who are you? What is chicken dinner?",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
style="whispering", # Azure-specific: cheerful, sad, angry, whispering, etc.
)
response.stream_to_file("speech.mp3")
스타일 + 강도 + 역할 (Style with Degree and Role)
from litellm import speech
response = speech(
model="azure/speech/azure-tts",
voice="en-US-AriaNeural",
input="Good morning! How are you today?",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
style="cheerful", # Azure-specific: Speaking style
styledegree="2", # Azure-specific: 0.01 to 2 (intensity)
role="SeniorFemale", # Azure-specific: Girl, Boy, SeniorFemale, etc.
)
response.stream_to_file("speech.mp3")
다국어 음성 언어 오버라이드
from litellm import speech
response = speech(
model="azure/speech/azure-tts",
voice="en-US-AvaMultilingualNeural", # Multilingual voice
input="आप कौन हैं? चिकन डिनर क्या है?", # Hindi text
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
lang="hi-IN", # Azure-specific: Override language
)
response.stream_to_file("speech.mp3")
Azure 전용 파라미터 참조
| 파라미터 | 설명 | 예시 값 | 비고 |
|---|---|---|---|
| style | 말하기 스타일 | cheerful, sad, angry, excited, friendly, hopeful, shouting, terrified, unfriendly, whispering | 특정 음성만 지원. Azure 음성 스타일 문서 참고 |
| styledegree | 스타일 강도 | 0.01 ~ 2 | 값이 높을수록 강함. 기본값 1 |
| role | 음성 역할 | Girl, Boy, YoungAdultFemale, YoungAdultMale, OlderAdultFemale, OlderAdultMale, SeniorFemale, SeniorMale | 특정 음성만 지원 |
| lang | 언어 코드 | es-ES, fr-FR, de-DE, hi-IN 등 | 다국어 음성용. 기본 언어 오버라이드 |
비동기 지원 (Async Support)
import asyncio
from litellm import aspeech
from pathlib import Path
async def generate_speech():
response = await aspeech(
model="azure/speech/azure-tts",
voice="alloy",
input="Hello from async",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
)
speech_file_path = Path(__file__).parent / "speech.mp3"
response.stream_to_file(speech_file_path)
asyncio.run(generate_speech())
지역 엔드포인트 (Regional Endpoints)
{region}을 Azure 리소스 지역으로 바꾸세요:
- US East:
https://eastus.tts.speech.microsoft.com - US West:
https://westus.tts.speech.microsoft.com - Europe West:
https://westeurope.tts.speech.microsoft.com - Asia Southeast:
https://southeastasia.tts.speech.microsoft.com
고급 기능 (Advanced Features)
사용자 지정 신경망 음성
전체 음성 이름을 전달하면 어떤 Azure 신경망 음성이든 사용할 수 있어요. 사용 가능한 음성은 Azure Speech Gallery에서 확인할 수 있어요.
response = speech(
model="azure/speech/azure-tts",
voice="en-US-AriaNeural", # Direct Azure voice name
input="Using a specific neural voice",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
)
에러 처리 (Error Handling)
from litellm import speech
from litellm.exceptions import APIError
try:
response = speech(
model="azure/speech/azure-tts",
voice="alloy",
input="Test message",
api_base="https://eastus.tts.speech.microsoft.com",
api_key=os.environ["AZURE_TTS_API_KEY"],
)
except APIError as e:
print(f"Azure Speech error: {e}")