> 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 varias solicitudes

> **Note**
>
> **Guía práctica** · Da por hecho que has completado la [guía de inicio rápido de ElevenAPI](/docs/es/eleven-api/quickstart).

Al convertir una gran cantidad de texto en audio, es posible que notes cambios bruscos en la prosodia de un fragmento a otro. Esto puede ser especialmente perceptible al convertir texto que abarca varios párrafos o secciones. Para mantener la prosodia de la voz entre varios fragmentos, puedes usar la función de unión de solicitudes.

Esta función te permite proporcionar contexto sobre lo que ya se ha generado y lo que se generará después, lo que ayuda a mantener una voz y una prosodia coherentes en todo el texto.

> **Info**
>
> La unión de solicitudes no está disponible para el modelo `eleven_v3`.

Aquí tienes un ejemplo sin unión de solicitudes:

Y el mismo ejemplo con unión de solicitudes:

## Cómo usar la unión de solicitudes

La unión de solicitudes es más sencilla cuando usas los SDK de ElevenLabs.

> **Note**
>
> Esta guía da por hecho que has [configurado tu clave de API y el SDK](/docs/es/eleven-api/quickstart). Completa
> primero la guía de inicio rápido si aún no lo has hecho.

#### Une varias solicitudes

Crea un archivo llamado `example.py` o `example.mts`, según el lenguaje que prefieras, y añade el siguiente código:

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

#### Ejecuta el código

```python
python example.py
```

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

Deberías escuchar el audio unido reproducirse.

## Preguntas frecuentes

#### ¿Cómo funciona la unión de solicitudes con streaming?

Para usar los ID de solicitud de una solicitud anterior como condicionamiento, esta debe haberse procesado por completo. En el caso del streaming, esto significa que el audio debe leerse completamente del cuerpo de la respuesta.

#### ¿Qué diferencia supone la unión de solicitudes?

La diferencia depende del modelo, la voz y la configuración de voz utilizados.

#### ¿Cuánto tiempo pueden tener los ID de solicitud?

Los ID de solicitud no deben tener más de dos horas.

#### ¿La unión de solicitudes está disponible en todos los planes?

Sí, salvo si eres un usuario enterprise con requisitos de privacidad más estrictos.

## Próximos pasos

#### [Streaming de Texto a Voz](/docs/es/eleven-api/guides/how-to/text-to-speech/streaming)

Transmite el audio progresivamente a medida que se genera para reproducirlo con menor latencia.

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

Referencia completa de los parámetros de unión de solicitudes.