> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-es/cabezas-parlantes/sadtalker.md).

# SadTalker

Crea videos de cabezas parlantes a partir de audio e imágenes en Clore.ai

Anima rostros con audio para crear videos realistas de cabeza parlante.

{% hint style="success" %}
Todos los ejemplos se pueden ejecutar en servidores GPU alquilados a través de [Marketplace de CLORE.AI](https://clore.ai/marketplace).
{% endhint %}

## Alquilar en CLORE.AI

1. Visita [Marketplace de CLORE.AI](https://clore.ai/marketplace)
2. Filtra por tipo de GPU, VRAM y precio
3. Elige **Bajo demanda** (tarifa fija) o **Spot** (precio ofertado)
4. Configura tu pedido:
   * Selecciona la imagen de Docker
   * Configura los puertos (TCP para SSH, HTTP para interfaces web)
   * Añade variables de entorno si es necesario
   * Introduce el comando de inicio
5. Selecciona el método de pago: **CLORE**, **BTC**, o **USDT/USDC**
6. Crea el pedido y espera al despliegue

### Accede a tu servidor

* Encuentra los detalles de conexión en **Mis pedidos**
* Interfaces web: Usa la URL del puerto HTTP
* SSH: `ssh -p <port> root@<proxy-address>`

## ¿Qué es SadTalker?

SadTalker genera videos parlantes:

* Sincronización labial con cualquier audio
* Movimientos naturales de cabeza
* Funciona con una sola imagen
* Control de expresión

## Requisitos

| Modo            | VRAM | Recomendado |
| --------------- | ---- | ----------- |
| Básico          | 4GB  | RTX 3060    |
| Alta calidad    | 6GB  | RTX 3080    |
| Rostro completo | 8GB  | RTX 4080    |

## Despliegue rápido

**Imagen de Docker:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel
```

**Puertos:**

```
22/tcp
7860/http
```

**Comando:**

```bash
cd /workspace && \\
git clone https://github.com/OpenTalker/SadTalker.git && \
cd SadTalker && \
pip install -r requirements.txt && \\
bash scripts/download_models.sh && \
python app.py
```

## Accediendo a tu servicio

Después del despliegue, encuentra tu `http_pub` URL en **Mis pedidos**:

1. Ve a **Mis pedidos** página
2. Haz clic en tu pedido
3. Encuentra la `http_pub` URL (p. ej., `abc123.clorecloud.net`)

Usa `https://YOUR_HTTP_PUB_URL` en lugar de `localhost` en los ejemplos a continuación.

## Instalación

```bash
git clone https://github.com/OpenTalker/SadTalker.git
cd SadTalker

pip install torch torchvision torchaudio
pip install -r requirements.txt

# Descargar modelos preentrenados
bash scripts/download_models.sh
```

## Uso básico

### Línea de comandos

```bash
python inference.py \
    --driven_audio audio.wav \
    --source_image face.jpg \
    --result_dir ./results \
    --enhancer gfpgan
```

### API de Python

```python
from src.facerender.animate import AnimateFromCoeff
from src.generate_batch import get_data
from src.generate_facerender_batch import get_facerender_data
import torch

class SadTalker:
    def __init__(self):
        self.device = "cuda"
        # Inicializar modelos...

    def generate(self, source_image, driven_audio, **kwargs):
        # Procesar audio e imagen
        # Generar animación
        # Devolver la ruta del video
        pass

# Uso
sadtalker = SadTalker()
video_path = sadtalker.generate(
    source_image="face.jpg",
    driven_audio="speech.wav"
)
```

## Con mejora facial

```bash

# Usando GFPGAN para mejorar el rostro
python inference.py \
    --driven_audio audio.wav \
    --source_image face.jpg \
    --enhancer gfpgan \
    --result_dir ./results

# Usando Real-ESRGAN para la imagen completa
python inference.py \
    --driven_audio audio.wav \
    --source_image face.jpg \
    --enhancer realesrgan \
    --result_dir ./results
```

## Parámetros

```bash
python inference.py \
    --driven_audio audio.wav \
    --source_image face.jpg \
    --pose_style 0 \           # 0-46 estilos de movimiento de cabeza
    --expression_scale 1.0 \   # Intensidad de la expresión
    --still \                  # Movimiento mínimo de cabeza
    --preprocess crop \        # recortar, redimensionar, completo
    --size 256 \               # Tamaño de salida
    --enhancer gfpgan
```

### Estilos de pose

| Rango | Efecto                 |
| ----- | ---------------------- |
| 0-5   | Movimientos sutiles    |
| 6-20  | Movimientos normales   |
| 21-46 | Movimientos expresivos |

## Procesamiento por lotes

```python
import os
import subprocess

def generate_talking_video(image_path, audio_path, output_dir):
    cmd = [
        "python", "inference.py",
        "--driven_audio", audio_path,
        "--source_image", image_path,
        "--result_dir", output_dir,
        "--enhancer", "gfpgan"
    ]
    subprocess.run(cmd, check=True)

# Procesar varias imágenes con el mismo audio
images = ["person1.jpg", "person2.jpg", "person3.jpg"]
audio = "speech.wav"

for i, img in enumerate(images):
    output = f"./results/video_{i}"
    generate_talking_video(img, audio, output)
```

## Interfaz de Gradio

```python
import gradio as gr
import subprocess
import tempfile
import os

def generate_video(image, audio, pose_style, expression_scale, enhancer):
    with tempfile.TemporaryDirectory() as tmpdir:
        # Guardar entradas
        image_path = os.path.join(tmpdir, "input.jpg")
        audio_path = os.path.join(tmpdir, "audio.wav")
        image.save(image_path)

        # Guardar audio
        import soundfile as sf
        sf.write(audio_path, audio[1], audio[0])

        # Generar
        cmd = [
            "python", "inference.py",
            "--driven_audio", audio_path,
            "--source_image", image_path,
            "--result_dir", tmpdir,
            "--pose_style", str(pose_style),
            "--expression_scale", str(expression_scale),
            "--enhancer", enhancer
        ]
        subprocess.run(cmd, check=True)

        # Buscar video de salida
        for f in os.listdir(tmpdir):
            if f.endswith(".mp4"):
                return os.path.join(tmpdir, f)

    return None

demo = gr.Interface(
    fn=generate_video,
    inputs=[
        gr.Image(type="pil", label="Rostro de origen"),
        gr.Audio(label="Audio de referencia"),
        gr.Slider(0, 46, value=0, step=1, label="Estilo de pose"),
        gr.Slider(0.5, 1.5, value=1.0, step=0.1, label="Escala de expresión"),
        gr.Dropdown(["gfpgan", "realesrgan", "none"], value="gfpgan", label="Mejorador")
    ],
    outputs=gr.Video(label="Video generado"),
    title="SadTalker - Generación de cabeza parlante"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## Servidor API

```python
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import FileResponse
import tempfile
import subprocess
import os

app = FastAPI()

@app.post("/generate")
async def generate(
    image: UploadFile = File(...),
    audio: UploadFile = File(...),
    pose_style: int = 0,
    expression_scale: float = 1.0
):
    with tempfile.TemporaryDirectory() as tmpdir:
        # Guardar archivos subidos
        image_path = os.path.join(tmpdir, "input.jpg")
        audio_path = os.path.join(tmpdir, "audio.wav")

        with open(image_path, "wb") as f:
            f.write(await image.read())
        with open(audio_path, "wb") as f:
            f.write(await audio.read())

        # Generar
        cmd = [
            "python", "inference.py",
            "--driven_audio", audio_path,
            "--source_image", image_path,
            "--result_dir", tmpdir,
            "--pose_style", str(pose_style),
            "--expression_scale", str(expression_scale),
            "--enhancer", "gfpgan"
        ]
        subprocess.run(cmd, check=True)

        # Devolver video
        for f in os.listdir(tmpdir):
            if f.endswith(".mp4"):
                return FileResponse(os.path.join(tmpdir, f), media_type="video/mp4")

# Ejecutar: uvicorn server:app --host 0.0.0.0 --port 8000
```

## Texto a voz + SadTalker

Flujo completo:

```python
import subprocess
from TTS.api import TTS

def text_to_talking_video(text, image_path, output_path):
    # Generar voz con TTS
    tts = TTS("tts_models/en/ljspeech/tacotron2-DDC")
    audio_path = "temp_audio.wav"
    tts.tts_to_file(text=text, file_path=audio_path)

    # Generar video parlante
    cmd = [
        "python", "inference.py",
        "--driven_audio", audio_path,
        "--source_image", image_path,
        "--result_dir", output_path,
        "--enhancer", "gfpgan"
    ]
    subprocess.run(cmd, check=True)

# Uso
text_to_talking_video(
    "Hello, welcome to our presentation. Today we'll discuss AI.",
    "presenter.jpg",
    "./output"
)
```

## Control de expresión

```python

# Expresión mínima (estilo presentador de noticias)
cmd = [
    "python", "inference.py",
    "--driven_audio", "audio.wav",
    "--source_image", "face.jpg",
    "--expression_scale", "0.5",
    "--still"  # Reduce el movimiento de cabeza
]

# Expresivo (personaje animado)
cmd = [
    "python", "inference.py",
    "--driven_audio", "audio.wav",
    "--source_image", "face.jpg",
    "--expression_scale", "1.5",
    "--pose_style", "30"
]
```

## Configuración de calidad

| Ajuste                | Velocidad | Calidad |
| --------------------- | --------- | ------- |
| Sin mejorador, 256 px | Rápido    | Básico  |
| GFPGAN, 256 px        | Medio     | Bueno   |
| GFPGAN, 512 px        | Lento     | Mejor   |
| RealESRGAN, 512 px    | Más lento | Mejor   |

## Opciones de preprocesamiento

```bash

# Recortar - enfocar en el rostro (recomendado)
--preprocess crop

# Redimensionar - redimensionar la imagen completa
--preprocess resize

# Completo - usar la imagen completa
--preprocess full
```

## Solución de problemas

### Rostro no detectado

* Usa una imagen clara y frontal del rostro
* Buena iluminación
* Evita oclusiones (gafas, cabello)

### Problemas de sincronización de audio

* Usa archivos WAV de 16 kHz
* Evita la música de fondo
* Solo habla clara

### Movimiento entrecortado

* Aumenta ligeramente expression\_scale
* Prueba un pose\_style diferente
* Usa audio más largo

### Sin memoria

* Reduce el tamaño de salida
* Desactiva el mejorador
* Usa preprocesamiento de recorte

## Rendimiento

| Resolución      | GPU      | Tiempo (video de 10 s) |
| --------------- | -------- | ---------------------- |
| 256 px          | RTX 3060 | \~30 s                 |
| 256 px          | RTX 4090 | \~15 s                 |
| 512 px + GFPGAN | RTX 4090 | \~45 s                 |

## Estimación de costos

Tarifas típicas del marketplace de CLORE.AI (a partir de 2024):

| GPU       | Tarifa por hora | Tarifa diaria | Sesión de 4 horas |
| --------- | --------------- | ------------- | ----------------- |
| RTX 3060  | \~$0.03         | \~$0.70       | \~$0.12           |
| RTX 3090  | \~$0.06         | \~$1.50       | \~$0.25           |
| RTX 4090  | \~$0.10         | \~$2.30       | \~$0.40           |
| A100 40GB | \~$0.17         | \~$4.00       | \~$0.70           |
| A100 80GB | \~$0.25         | \~$6.00       | \~$1.00           |

*Los precios varían según el proveedor y la demanda. Consulta* [*Marketplace de CLORE.AI*](https://clore.ai/marketplace) *las tarifas actuales.*

**Ahorra dinero:**

* Usa el **Spot** mercado para trabajo interrumpible — alrededor de un tercio de los servidores fija el precio spot por debajo del precio bajo demanda (mediana de \~13% de descuento), el resto lo iguala
* Paga con **CLORE** tokens
* Compara precios entre distintos proveedores

## Siguientes pasos

* [Wav2Lip](/guides/guides_v2-es/cabezas-parlantes/wav2lip.md) - Sincronización labial alternativa
* [Bark TTS](/guides/guides_v2-es/audio-y-voz/bark-tts.md) - Generar voz
* [XTTS](/guides/guides_v2-es/audio-y-voz/xtts-coqui.md) - Clonación de voz + TTS


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-es/cabezas-parlantes/sadtalker.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
