여러 요청 이어 붙이기

이 가이드에서는 여러 텍스트 청크 또는 생성 작업 전반에서 음성 운율을 유지하는 방법을 보여드립니다.

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

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

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

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

다음은 요청 연결을 사용하지 않은 예시입니다.

다음은 요청 연결을 적용한 동일한 예시입니다.

요청 연결 사용 방법

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

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

1

여러 요청 연결하기

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

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",
previous_request_ids=request_ids
) 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시간 이내여야 합니다.

예. 단, 더 높은 수준의 개인정보 보호가 필요한 엔터프라이즈 사용자는 예외입니다.

다음 단계