> 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.

# Mehrere Anfragen zusammenfügen

> **Note**
>
> **Anleitung** · Setzt voraus, dass Sie den [ElevenAPI- Schnellstart](/docs/de/eleven-api/quickstart) abgeschlossen haben.

Wenn Sie einen großen Textumfang in Audio umwandeln, kann es von einem Abschnitt zum nächsten zu abrupten Änderungen in der Prosodie kommen. Dies kann besonders auffallen, wenn Sie Text umwandeln, der sich über mehrere Absätze oder Abschnitte erstreckt. Um die Stimmprosodie über mehrere Abschnitte hinweg beizubehalten, können Sie die Funktion Request Stitching verwenden.

Mit dieser Funktion können Sie Kontext dazu angeben, was bereits generiert wurde und was künftig generiert wird. So bleiben Stimme und Prosodie im gesamten Text konsistent.

> **Info**
>
> Request Stitching ist für das Modell `eleven_v3` nicht verfügbar.

Hier ist ein Beispiel ohne Request Stitching:

Und dasselbe Beispiel mit Request Stitching:

## Request Stitching verwenden

Request Stitching lässt sich am einfachsten mit den ElevenLabs SDKs verwenden.

> **Note**
>
> Diese Anleitung setzt voraus, dass Sie [Ihren API-Schlüssel und Ihr SDK eingerichtet](/docs/de/eleven-api/quickstart) haben. Schließen Sie
> zuerst den Schnellstart ab, falls Sie dies noch nicht getan haben.

#### Mehrere Anfragen zusammenführen

Erstellen Sie je nach bevorzugter Sprache eine neue Datei mit dem Namen `example.py` oder `example.mts` und fügen Sie den folgenden Code hinzu:

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

#### Code ausführen

```python
python example.py
```

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

Sie sollten das zusammengeführte Audio hören.

## FAQ

#### Wie funktioniert Request Stitching mit Streaming?

Um die Anfrage-IDs einer vorherigen Anfrage zur Konditionierung zu verwenden, muss diese vollständig verarbeitet sein. Bei Streaming bedeutet das, dass das Audio vollständig aus dem Response-Body gelesen werden muss.

#### Wie groß ist der Unterschied durch Request Stitching?

Der Unterschied hängt vom verwendeten Modell, der Stimme und den Stimmeinstellungen ab.

#### Wie alt dürfen die Anfrage-IDs sein?

Die Anfrage-IDs sollten nicht älter als zwei Stunden sein.

#### Ist Request Stitching in jedem Tarif verfügbar?

Ja, außer Sie sind ein Enterprise-Nutzer mit erhöhten Datenschutzanforderungen.

## Nächste Schritte

#### [TTS-Streaming](/docs/de/eleven-api/guides/how-to/text-to-speech/streaming)

Streamen Sie Audio während der Generierung schrittweise für eine Wiedergabe mit geringerer Latenz.

#### [API-Referenz](/docs/de/api-reference/text-to-speech/stream)

Vollständige Referenz der Request-Stitching-Parameter.