# LatentSync

> LatentSync is a video-to-video model that generates lip sync animations from audio using advanced algorithms for high-quality synchronization.


## Overview

- **Endpoint**: `https://fal.run/fal-ai/latentsync`
- **Model ID**: `fal-ai/latentsync`
- **Category**: video-to-video
- **Kind**: inference
**Tags**: animation, lip sync



## Pricing

Your request will cost $0.2 for videos up to 40 seconds. For longer videos, you will be charged $0.005 per second of output video.

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`video_url`** (`string`, _required_):
  The URL of the video to generate the lip sync for.
  - Examples: "https://fal.media/files/koala/8teUPbRRMtAUTORDvqy0l.mp4"

- **`audio_url`** (`string`, _required_):
  The URL of the audio to generate the lip sync for.
  - Examples: "https://fal.media/files/lion/vyFWygmZsIZlUO4s0nr2n.wav"

- **`guidance_scale`** (`float`, _optional_):
  Guidance scale for the model inference Default value: `1`
  - Default: `1`
  - Range: `1` to `2`

- **`seed`** (`integer`, _optional_):
  Random seed for generation. If None, a random seed will be used.

- **`loop_mode`** (`Enum`, _optional_):
  Video loop mode when audio is longer than video. Options: pingpong, loop
  - Options: `"pingpong"`, `"loop"`



**Required Parameters Example**:

```json
{
  "video_url": "https://fal.media/files/koala/8teUPbRRMtAUTORDvqy0l.mp4",
  "audio_url": "https://fal.media/files/lion/vyFWygmZsIZlUO4s0nr2n.wav"
}
```

**Full Example**:

```json
{
  "video_url": "https://fal.media/files/koala/8teUPbRRMtAUTORDvqy0l.mp4",
  "audio_url": "https://fal.media/files/lion/vyFWygmZsIZlUO4s0nr2n.wav",
  "guidance_scale": 1
}
```


### Output Schema

The API returns the following output format:

- **`video`** (`File`, _required_):
  The generated video with the lip sync.



**Example Response**:

```json
{
  "video": {
    "url": "",
    "content_type": "image/png",
    "file_name": "z9RV14K95DvU.png",
    "file_size": 4404019
  }
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/latentsync \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "video_url": "https://fal.media/files/koala/8teUPbRRMtAUTORDvqy0l.mp4",
     "audio_url": "https://fal.media/files/lion/vyFWygmZsIZlUO4s0nr2n.wav"
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/latentsync",
    arguments={
        "video_url": "https://fal.media/files/koala/8teUPbRRMtAUTORDvqy0l.mp4",
        "audio_url": "https://fal.media/files/lion/vyFWygmZsIZlUO4s0nr2n.wav"
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/latentsync", {
  input: {
    video_url: "https://fal.media/files/koala/8teUPbRRMtAUTORDvqy0l.mp4",
    audio_url: "https://fal.media/files/lion/vyFWygmZsIZlUO4s0nr2n.wav"
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/latentsync)
- [API Documentation](https://fal.ai/models/fal-ai/latentsync/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/latentsync)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
