탐색으로 건너뛰기

여러 요청 연결하기

이 가이드에서는 여러 텍스트 청크/생성에 걸쳐 음성 운율을 유지하는 방법을 알아봅니다.

사용 방법 가이드 · ElevenAPI 빠른 시작을 완료했다고 가정합니다.

많은 양의 텍스트를 오디오로 변환할 때 청크 간에 운율이 갑자기 바뀌는 현상이 발생할 수 있습니다. 이는 여러 문단이나 섹션에 걸친 텍스트를 변환할 때 특히 눈에 띌 수 있습니다. 여러 청크에 걸쳐 음성 운율을 유지하려면 요청 연결 기능을 사용할 수 있습니다.

이 기능을 사용하면 이미 생성된 내용과 앞으로 생성될 내용에 대한 컨텍스트를 제공하여 전체 텍스트에서 일관된 음성과 운율을 유지할 수 있습니다.

요청 연결은 eleven_v3 모델에서 사용할 수 없습니다.

요청 연결을 사용하지 않은 예시는 다음과 같습니다.

요청 연결을 적용한 동일한 예시는 다음과 같습니다.

요청 연결 사용 방법

요청 연결은 ElevenLabs SDK를 사용할 때 가장 쉽게 적용할 수 있습니다.

이 가이드는 API 키와 SDK를 설정했다고 가정합니다. 아직 완료하지 않았다면 먼저 빠른 시작을 완료하세요.

1

여러 요청 연결하기

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

previous_request_ids에는 최대 3개의 요청 ID만 제공할 수 있습니다. 그보다 많으면 400 오류가 반환됩니다. 가장 최근 ID 3개를 전달하고, 현재 요청에 가장 가까운 요청을 마지막에 배치하세요.

import os
from io import BytesIO
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
from dotenv import load_dotenv
load_dotenv()
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
elevenlabs = ElevenLabs(
api_key=ELEVENLABS_API_KEY,
)
paragraphs = [
"The advent of technology has transformed countless sectors, with education ",
"standing out as one of the most significantly impacted fields.",
"In recent years, educational technology, or EdTech, has revolutionized the way ",
"teachers deliver instruction and students absorb information.",
"From interactive whiteboards to individual tablets loaded with educational software, ",
"technology has opened up new avenues for learning that were previously unimaginable.",
"One of the primary benefits of technology in education is the accessibility it provides.",
]
request_ids = []
audio_buffers = []
for paragraph in paragraphs:
# Usually we get back a stream from the convert function, but with_raw_response is
# used to get the headers from the response
with elevenlabs.text_to_speech.with_raw_response.convert(
text=paragraph,
voice_id="T7QGPtToiqH4S8VlIkMJ",
model_id="eleven_v4",
# The API accepts at most 3 previous request IDs
previous_request_ids=request_ids[-3:]
) as response:
request_ids.append(response._response.headers.get("request-id"))
# response._response.headers also contains useful information like 'character-cost',
# which shows the cost of the generation in characters.
audio_data = b''.join(chunk for chunk in response.data)
audio_buffers.append(BytesIO(audio_data))
combined_stream = BytesIO(b''.join(buffer.getvalue() for buffer in audio_buffers))
play(combined_stream)
2

코드 실행하기

python example.py

연결된 오디오가 재생되는 것을 들을 수 있습니다.

FAQ

이전 요청의 요청 ID를 컨디셔닝에 사용하려면 해당 요청이 완전히 처리되어야 합니다. 스트리밍의 경우 응답 본문에서 오디오를 완전히 읽어야 한다는 의미입니다.

차이는 사용하는 모델, 음성 및 음성 설정에 따라 달라집니다.

요청 ID는 2시간을 넘지 않아야 합니다.

예. 개인정보 보호 요구 사항이 강화된 엔터프라이즈 사용자가 아닌 경우 사용할 수 있습니다.

다음 단계