보이스 디자인 빠른 시작

이 가이드에서는 Voice Design API를 사용하여 텍스트 프롬프트로 음성을 디자인하는 방법을 알려드립니다.

이 가이드에서는 Voice Design API를 사용하여 프롬프트로 음성을 디자인하는 방법을 알려드립니다.

Voice Design API 사용하기

이 가이드는 API 키와 SDK를 설정했다고 가정합니다. 아직 설정하지 않았다면 먼저 빠른 시작 가이드를 완료하세요. 스피커로 오디오를 재생하려면 MPV 및/또는 ffmpeg가 필요할 수도 있습니다.

1

API 요청 보내기

프롬프트로 음성을 디자인하는 과정은 2단계로 이루어집니다.

  1. 프롬프트를 기반으로 미리보기를 생성합니다.
  2. 가장 좋은 미리보기를 선택하여 새 음성을 만듭니다.

먼저 프롬프트를 기반으로 미리보기를 생성하겠습니다.

사용할 언어에 따라 example.py 또는 example.mts라는 새 파일을 만들고 다음 코드를 추가하세요.

# example.py
from dotenv import load_dotenv
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import base64
load_dotenv()
elevenlabs = ElevenLabs(
api_key=os.getenv("ELEVENLABS_API_KEY"),
)
voices = elevenlabs.text_to_voice.design(
model_id="eleven_multilingual_ttv_v2",
voice_description="A massive evil ogre speaking at a quick pace. He has a silly and resonant tone.",
text="Your weapons are but toothpicks to me. Surrender now and I may grant you a swift end. I've toppled kingdoms and devoured armies. What hope do you have against me?",
)
for preview in voices.previews:
# Convert base64 to audio buffer
audio_buffer = base64.b64decode(preview.audio_base_64)
print(f"Playing preview: {preview.generated_voice_id}")
play(audio_buffer)
2

코드 실행하기

python example.py

생성된 음성 미리보기가 스피커를 통해 한 번에 하나씩 재생됩니다.

3

생성한 음성을 라이브러리에 추가하기

미리보기를 생성하고 가장 마음에 드는 음성을 선택했다면 생성된 음성 ID를 통해 보이스 라이브러리에 추가하여 다른 API에서 사용할 수 있습니다.

voice = elevenlabs.text_to_voice.create(
voice_name="Jolly giant",
voice_description="A huge giant, at least as tall as a building. A deep booming voice, loud and jolly.",
# The generated voice ID of the preview you want to use,
# using the first in the list for this example
generated_voice_id=voices.previews[0].generated_voice_id
)
print(voice.voice_id)

다음 단계