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

# Unir várias solicitações

> **Note**
>
> **Guia prático** · Pressupõe que você tenha concluído o [início rápido da ElevenAPI](/docs/pt/eleven-api/quickstart).

Ao converter um grande volume de texto em áudio, você pode perceber mudanças bruscas na prosódia de um trecho para outro. Isso pode ser especialmente perceptível ao converter textos que abrangem vários parágrafos ou seções. Para manter a prosódia da voz em vários trechos, você pode usar o recurso de Costura de Solicitações.

Esse recurso permite fornecer contexto sobre o que já foi gerado e o que será gerado futuramente, ajudando a manter uma voz e prosódia consistentes em todo o texto.

> **Info**
>
> A costura de solicitações não está disponível para o modelo `eleven_v3`.

Veja um exemplo sem a Costura de Solicitações:

E o mesmo exemplo com a Costura de Solicitações:

## Como usar a Costura de Solicitações

A Costura de Solicitações é mais fácil de usar com os SDKs da ElevenLabs.

> **Note**
>
> Este guia pressupõe que você já [configurou sua chave de API e o SDK](/docs/pt/eleven-api/quickstart). Conclua
> o início rápido primeiro, caso ainda não tenha feito isso.

#### Costure várias solicitações

Crie um novo arquivo chamado `example.py` ou `example.mts`, dependendo da linguagem escolhida, e adicione o código abaixo:

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

#### Execute o código

```python
python example.py
```

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

Você deverá ouvir o áudio combinado e costurado sendo reproduzido.

## Perguntas frequentes

#### Como a Costura de Solicitações funciona com streaming?

Para usar os IDs de solicitação de uma solicitação anterior como condicionamento, ela precisa ter sido completamente processada. No caso de streaming, isso significa que o áudio precisa ser lido por completo do corpo da resposta.

#### Qual é o impacto da Costura de Solicitações?

A diferença depende do modelo, da voz e das configurações de voz usadas.

#### Qual pode ser a idade dos IDs de solicitação?

Os IDs de solicitação não devem ter mais de duas horas.

#### A Costura de Solicitações está disponível em todos os planos?

Sim, a menos que você seja um usuário corporativo com requisitos de privacidade maiores.

## Próximas etapas

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

Transmita o áudio progressivamente conforme ele é gerado para reprodução com menor latência.

#### [Referência da API](/docs/pt/api-reference/text-to-speech/stream)

Referência completa dos parâmetros de costura de solicitações.