> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 複数リクエストの連結

> **Note**
>
> **ハウツーガイド** · [ElevenAPI クイックスタート](/docs/ja/eleven-api/quickstart)を完了していることを前提としています。

大量のテキストをオーディオに変換すると、チャンクごとにプロソディが急激に変化することがあります。これは、複数の段落やセクションにまたがるテキストを変換する場合に特に顕著です。複数のチャンクにわたって音声のプロソディを維持するには、リクエストスティッチング機能を使用します。

この機能では、すでに生成された内容と今後生成される内容のコンテキストを指定できるため、テキスト全体で一貫した音声とプロソディを維持できます。

> **Info**
>
> リクエストスティッチングは`eleven_v3`モデルでは利用できません。

以下は、リクエストスティッチングを使用しない例です。

次は、リクエストスティッチングを使用した同じ例です。

## リクエストスティッチングの使い方

リクエストスティッチングは、ElevenLabs SDKを使用すると簡単に利用できます。

> **Note**
>
> このガイドは、[APIキーとSDKを設定済み](/docs/ja/eleven-api/quickstart)であることを前提としています。まだの場合は、先にクイックスタートを完了してください。

#### 複数のリクエストをつなげる

使用する言語に応じて、`example.py`または`example.mts`という新しいファイルを作成し、次のコードを追加します。

```python
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)
```

```typescript
import "dotenv/config";
import { ElevenLabsClient, play } from "@elevenlabs/elevenlabs-js";
import { Readable } from "node:stream";

const elevenlabs = new ElevenLabsClient({
    apiKey: process.env.ELEVENLABS_API_KEY,
});

const 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.",
];

const requestIds: string[] = [];
const audioBuffers: Buffer[] = [];

for (const paragraph of paragraphs) {
    // Usually we get back a stream from the convert function, but withRawResponse() is
    // used to get the headers from the response
    const response = await elevenlabs.textToSpeech
        .convert("T7QGPtToiqH4S8VlIkMJ", {
            text: paragraph,
            modelId: "eleven_v4",
            previousRequestIds: requestIds,
        })
        .withRawResponse();

    // response.rawResponse.headers also contains useful information like 'character-cost',
    // which shows the cost of the generation in characters.

    requestIds.push(response.rawResponse.headers.get("request-id") ?? "");

    // Convert stream to buffer
    const chunks: Buffer[] = [];
    for await (const chunk of response.data) {
        chunks.push(Buffer.from(chunk));
    }
    audioBuffers.push(Buffer.concat(chunks));
}

// Create a single readable stream from all buffers
const combinedStream = Readable.from(Buffer.concat(audioBuffers));

play(combinedStream);
```

#### コードを実行する

```python
python example.py
```

```typescript
npx tsx example.mts
```

結合・スティッチされたオーディオが再生されます。

## よくある質問

#### ストリーミングでリクエストスティッチングを使用するには？

前のリクエストのリクエストIDをコンディショニングに使用するには、そのリクエストが完全に処理されている必要があります。ストリーミングの場合、レスポンス本文からオーディオを最後まで読み取る必要があります。

#### リクエストスティッチングによる違いはどの程度ですか？

違いは、使用するモデル、音声、音声設定によって異なります。

#### リクエストIDはどのくらい前のものまで使用できますか？

リクエストIDは2時間以内のものである必要があります。

#### リクエストスティッチングはすべてのプランで利用できますか？

はい。ただし、プライバシー要件がより厳しいエンタープライズユーザーは除きます。

## 次のステップ

#### [TTSストリーミング](/docs/ja/eleven-api/guides/how-to/text-to-speech/streaming)

生成に合わせてオーディオを段階的にストリーミングし、低レイテンシーで再生します。

#### [APIリファレンス](/docs/ja/api-reference/text-to-speech/stream)

リクエストスティッチングのパラメータに関する完全なリファレンス。