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

# Łączenie wielu żądań

> **Note**
>
> **Przewodnik krok po kroku** · Zakłada, że masz za sobą [szybki start z ElevenAPI ](/docs/pl/eleven-api/quickstart).

Podczas zamiany dużej ilości tekstu na audio możesz zauważyć nagłe zmiany prozodii między fragmentami. Jest to szczególnie odczuwalne przy tekście obejmującym wiele akapitów lub sekcji. Aby zachować prozodię głosu w wielu fragmentach, użyj funkcji Request Stitching.

Ta funkcja pozwala podać kontekst tego, co już wygenerowano i co zostanie wygenerowane później, pomagając zachować spójny głos i prozodię w całym tekście.

> **Info**
>
> Request Stitching nie jest dostępne dla modelu `eleven_v3`.

Oto przykład bez Request Stitching:

A ten sam przykład z Request Stitching:

## Jak używać Request Stitching

Z Request Stitching najłatwiej skorzystać przez SDK ElevenLabs.

> **Note**
>
> Ten przewodnik zakłada, że [skonfigurowałeś klucz API i SDK](/docs/pl/eleven-api/quickstart). Jeśli jeszcze tego nie zrobiłeś, najpierw ukończ
> szybki start.

#### Połącz wiele żądań

Utwórz nowy plik o nazwie `example.py` lub `example.mts`, zależnie od wybranego języka, i dodaj poniższy kod:

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

#### Uruchom kod

```python
python example.py
```

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

Powinieneś usłyszeć połączone audio.

## FAQ

#### Jak Request Stitching działa ze streamingiem?

Aby użyć identyfikatorów żądań z poprzedniego żądania jako kontekstu, musi ono zostać w pełni przetworzone. W przypadku streamingu oznacza to, że audio musi zostać w całości odczytane z treści odpowiedzi.

#### Jak dużą różnicę daje Request Stitching?

Różnica zależy od użytego modelu, głosu i ustawień głosu.

#### Jak stare mogą być identyfikatory żądań?

Identyfikatory żądań nie powinny być starsze niż dwie godziny.

#### Czy Request Stitching jest dostępne w każdym planie?

Tak, chyba że jesteś użytkownikiem enterprise z podwyższonymi wymogami prywatności.

## Kolejne kroki

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

Przesyłaj audio stopniowo podczas generowania, aby skrócić opóźnienia odtwarzania.

#### [Dokumentacja API](/docs/pl/api-reference/text-to-speech/stream)

Pełna dokumentacja parametrów Request Stitching.