Vertex AI 텍스트 음성 변환
Vertex AI 텍스트 음성 변환 (Text to Speech)
Chirp3 HD 음성과 Gemini TTS를 사용하는 Google Cloud Text-to-Speech를 LiteLLM에서 사용하는 방법을 알아봐요.
출처: 문서
본문
| 속성 | 내용 |
|---|---|
| 설명 | Chirp3 HD 음성과 Gemini TTS를 갖춘 Google Cloud Text-to-Speech |
| LiteLLM 라우트 | vertex_ai/chirp (Chirp), vertex_ai/gemini-*-tts (Gemini) |
Chirp3 HD 음성
고품질 Chirp3 HD 음성을 갖춘 Google Cloud Text-to-Speech API.
빠른 시작
LiteLLM Python SDK
from litellm import speech
from pathlib import Path
speech_file_path = Path(__file__).parent / "speech.mp3"
response = speech(
model="vertex_ai/chirp",
voice="alloy", # OpenAI voice name - automatically mapped
input="Hello, this is Vertex AI Text to Speech",
vertex_project="your-project-id",
vertex_location="us-central1",
)
response.stream_to_file(speech_file_path)
LiteLLM AI Gateway
- config.yaml 설정:
model_list:
- model_name: vertex-tts
litellm_params:
model: vertex_ai/chirp
vertex_project: "your-project-id"
vertex_location: "us-central1"
vertex_credentials: "/path/to/service_account.json"
- Proxy 시작:
litellm --config /path/to/config.yaml
- 요청하기:
curl http://0.0.0.0:4000/v1/audio/speech \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "vertex-tts",
"voice": "alloy",
"input": "Hello, this is Vertex AI Text to Speech"
}' \
--output speech.mp3
import openai
client = openai.OpenAI(api_key="sk-", base_url="http://0.0.0.0:4000")
response = client.audio.speech.create(
model="vertex-tts",
voice="alloy",
input="Hello, this is Vertex AI Text to Speech",
)
response.stream_to_file("speech.mp3")
음성 매핑
LiteLLM은 OpenAI 음성 이름을 Google Cloud 음성으로 매핑해요. OpenAI 음성 또는 Google Cloud 음성을 직접 사용할 수 있어요.
| OpenAI 음성 | Google Cloud 음성 |
|---|---|
alloy |
en-US-Studio-O |
echo |
en-US-Studio-M |
fable |
en-GB-Studio-B |
onyx |
en-US-Wavenet-D |
nova |
en-US-Studio-O |
shimmer |
en-US-Wavenet-F |
Google Cloud 음성 직접 사용
from litellm import speech
# Pass Chirp3 HD voice name directly
response = speech(
model="vertex_ai/chirp",
voice="en-US-Chirp3-HD-Charon",
input="Hello with a Chirp3 HD voice",
vertex_project="your-project-id",
)
response.stream_to_file("speech.mp3")
Dict로 전달 (다국어):
from litellm import speech
# Pass as dict for full control over language and voice
response = speech(
model="vertex_ai/chirp",
voice={
"languageCode": "de-DE",
"name": "de-DE-Chirp3-HD-Charon",
},
input="Hallo, dies ist ein Test",
vertex_project="your-project-id",
)
response.stream_to_file("speech.mp3")
AI Gateway:
curl http://0.0.0.0:4000/v1/audio/speech \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "vertex-tts",
"voice": {"languageCode": "de-DE", "name": "de-DE-Chirp3-HD-Charon"},
"input": "Hallo, dies ist ein Test"
}' \
--output speech.mp3
사용 가능한 음성은 Google Cloud Text-to-Speech Console에서 찾아볼 수 있어요.
원시 SSML 전달
입력에 <speak> 태그가 있으면 LiteLLM이 자동으로 SSML로 감지하고 그대로 전달해요.
from litellm import speech
ssml = """
<speak>
Hello, world!
<break time="1s"/>
This is a test of the <say-as interpret-as="characters">text-to-speech</say-as> API.
</speak>
"""
response = speech(
model="vertex_ai/chirp",
voice="en-US-Studio-O",
input=ssml, # Auto-detected as SSML
vertex_project="your-project-id",
)
response.stream_to_file("speech.mp3")
SSML 모드 강제:
from litellm import speech
# Force SSML mode with use_ssml=True
response = speech(
model="vertex_ai/chirp",
voice="en-US-Studio-O",
input="Speaking slowly",
use_ssml=True,
vertex_project="your-project-id",
)
response.stream_to_file("speech.mp3")
지원 파라미터
| 파라미터 | 설명 | 값 |
|---|---|---|
voice |
음성 선택 | OpenAI 음성, Google Cloud 음성 이름, 또는 dict |
input |
변환할 텍스트 | 일반 텍스트 또는 SSML |
speed |
말하기 속도 | 0.25 ~ 4.0 (기본값: 1.0) |
response_format |
오디오 형식 | mp3, opus, wav, pcm, flac |
use_ssml |
SSML 모드 강제 | True / False |
비동기 사용법
import asyncio
from litellm import aspeech
async def main():
response = await aspeech(
model="vertex_ai/chirp",
voice="alloy",
input="Hello from async",
vertex_project="your-project-id",
)
response.stream_to_file("speech.mp3")
asyncio.run(main())
Gemini TTS
오디오 출력 능력을 갖춘 Gemini 모델을 chat completions API로 사용해요.
warning 제한 사항:
pcm16오디오 형식만 지원- 스트리밍은 아직 미지원
modalities: ["audio"]설정 필수- LiteLLM Proxy에서 사용할 때는 오디오 파라미터를 활성화하기 위해 요청 본문에
"allowed_openai_params": ["audio", "modalities"]를 포함해야 함
빠른 시작
from litellm import completion
import json
# Load credentials
with open('path/to/service_account.json', 'r') as file:
vertex_credentials = json.dumps(json.load(file))
response = completion(
model="vertex_ai/gemini-2.5-flash-preview-tts",
messages=[{"role": "user", "content": "Say hello in a friendly voice"}],
modalities=["audio"],
audio={
"voice": "Kore",
"format": "pcm16"
},
vertex_credentials=vertex_credentials
)
print(response)
AI Gateway:
model_list:
- model_name: gemini-tts
litellm_params:
model: vertex_ai/gemini-2.5-flash-preview-tts
vertex_project: "your-project-id"
vertex_location: "us-central1"
vertex_credentials: "/path/to/service_account.json"
curl http://0.0.0.0:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ***" \
-d '{
"model": "gemini-tts",
"messages": [{"role": "user", "content": "Say hello in a friendly voice"}],
"modalities": ["audio"],
"audio": {"voice": "Kore", "format": "pcm16"},
"allowed_openai_params": ["audio", "modalities"]
}'
지원 모델
vertex_ai/gemini-2.5-flash-preview-ttsvertex_ai/gemini-2.5-pro-preview-tts
사용 가능한 음성은 Gemini TTS 문서를 참고해요.
고급 사용법
from litellm import completion
response = completion(
model="vertex_ai/gemini-2.5-pro-preview-tts",
messages=[
{"role": "system", "content": "You are a helpful assistant that speaks clearly."},
{"role": "user", "content": "Explain quantum computing in simple terms"}
],
modalities=["audio"],
audio={"voice": "Charon", "format": "pcm16"},
temperature=0.7,
max_tokens=150,
vertex_credentials=vertex_credentials
)
더 알아보기 (Learn more)
- Google Cloud Text-to-Speech 문서
- Gemini TTS 문서