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

# Unire più richieste

> **Note**
>
> **Guida pratica** · Presuppone che tu abbia completato la [guida rapida di ElevenAPI](/docs/it/eleven-api/quickstart).

Quando converti una grande quantità di testo in audio, potresti riscontrare cambiamenti bruschi nella prosodia tra un blocco e l'altro. Questo può essere particolarmente evidente quando converti un testo che comprende più paragrafi o sezioni. Per mantenere la prosodia della voce su più blocchi, puoi usare la funzionalità Request Stitching.

Questa funzionalità ti consente di fornire il contesto di ciò che è già stato generato e di ciò che verrà generato in seguito, aiutandoti a mantenere una voce e una prosodia coerenti nell'intero testo.

> **Info**
>
> Request Stitching non è disponibile per il modello `eleven_v3`.

Ecco un esempio senza Request Stitching:

E lo stesso esempio con Request Stitching:

## Come usare Request Stitching

Request Stitching è più semplice da usare con gli SDK di ElevenLabs.

> **Note**
>
> Questa guida presuppone che tu abbia [configurato la chiave API e l'SDK](/docs/it/eleven-api/quickstart). Completa
> prima la guida rapida, se non l'hai ancora fatto.

#### Unisci più richieste

Crea un nuovo file denominato `example.py` o `example.mts`, a seconda del linguaggio che preferisci, e aggiungi il seguente codice:

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

#### Esegui il codice

```python
python example.py
```

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

Dovresti sentire l'audio combinato e unito riprodotto.

## Domande frequenti

#### Come funziona Request Stitching con lo streaming?

Per usare gli ID richiesta di una richiesta precedente come condizionamento, questa deve essere stata elaborata completamente. Nel caso dello streaming, ciò significa che l'audio deve essere letto completamente dal body della risposta.

#### Che differenza fa Request Stitching?

La differenza dipende dal modello, dalla voce e dalle impostazioni vocali usate.

#### Quanto possono essere vecchi gli ID richiesta?

Gli ID richiesta non devono avere più di due ore.

#### Request Stitching è disponibile in tutti i piani?

Sì, a meno che tu non sia un utente enterprise con requisiti di privacy più elevati.

## Passaggi successivi

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

Trasmetti l'audio progressivamente mentre viene generato per una riproduzione con minore latenza.

#### [Riferimento API](/docs/it/api-reference/text-to-speech/stream)

Riferimento completo dei parametri di request stitching.