> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magichour.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Lip Sync API

> Synchronize lip movements in videos with new audio tracks.

export const ToolSection = ({type = "image", outputs = [], title = "", productSlug = "", apiSlug = ""}) => <>
    <CardGroup cols={2}>
      <Card title={`${title} API reference`} icon="webhook" horizontal href={`/api-reference/${type}-projects/${apiSlug}`}>
        Request fields, responses, and examples
      </Card>
      <Card title="API quickstart" icon="forward-fast" horizontal href="/get-started/quick-start">
        Install an SDK and complete your first generation
      </Card>
    </CardGroup>

    <p>
      Check <a href="/billing/overview">API pricing</a> and <a href="/api-reference/models">model credit costs</a>, then <a href={`https://magichour.ai/developer?tab=api-keys&ref=docs-tool-${apiSlug}&utm_source=docs&utm_medium=referral&utm_campaign=tools`}>create an API key</a>.
    </p>
    <p>
      To try {title} without code, use the <a href={`https://magichour.ai/products/${productSlug}${productSlug.includes("?") ? "&" : "?"}utm_source=docs&utm_medium=referral&utm_campaign=tools`}>browser tool</a>.
    </p>

    {outputs && outputs.length > 0 && <Tabs>
        {outputs.map((output, idx) => <Tab key={idx} title={`Example Output ${idx + 1}`}>
            <Frame>
              {type === "video" ? <video controls preload="metadata" playsInline className="rounded-lg h-80" src={`${output.src}#t=0.001`} type={`${output.src?.endsWith("mp4") ? 'video/mp4' : "video/webm"}`}>
                </video> : type === "audio" ? <audio controls preload="metadata" className="w-full" src={output.src}>
                  Your browser does not support the audio element.
                </audio> : <img height="320" className="rounded-lg h-80" src={output.src} alt={`${title} example output ${idx + 1}`} />}
            </Frame>
          </Tab>)}
      </Tabs>}

  </>;

## Overview

Lip Sync synchronizes lip movements in videos with new audio tracks using advanced AI motion analysis. The API creates realistic lip-sync animation that matches speech patterns, timing, and mouth movements for natural-looking results.

**Processing:** See recent [typical API-job times](/api-reference/processing-times). Jobs run
asynchronously, and duration varies with the input, selected settings, and queue load.

<ToolSection
  title="Lip Sync"
  productSlug="lip-sync"
  apiSlug="lip-sync"
  type="video"
  outputs={[
{
  src: "https://videos.magichour.ai/cm9zpj13l06r16y0z70fklvm8/video.mp4",
},
{
  src: "https://videos.magichour.ai/clvu7b0k802oq8ypu0wcvt8fu/video.mp4",
},
]}
/>

## How It Works

1. **Provide a source video** - Upload the video with the person speaking
2. **Provide audio** - Upload the new audio track to sync to
3. **API processes the video** - AI analyzes audio and animates lip movements
4. **Download the result** - Retrieve your lip-synced video

## Use Cases

For a complete voice-to-video workflow, follow the [lip-sync starter recipe](/get-started/starter-recipes). It covers uploading your video and voiceover, submitting the lip-sync job, and downloading the result.

* **Dubbing and localization** - Translate videos to new languages with matching lips
* **Personalized messages** - Create custom video messages with any voice
* **Educational content** - Produce training videos with voiceovers
* **Entertainment** - Create fun lip-sync content for social media
* **Accessibility** - Add voiceovers to silent video content

## Best Practices

### Video Requirements

<Tip>
  **Clear, front-facing footage works best** - Ensure the speaker's face and lips are clearly
  visible throughout.
</Tip>

* **Face visibility** - Full face visible with minimal obstructions
* **Good lighting** - Even lighting on the face
* **Stable framing** - Face stays in frame throughout
* **Moderate motion** - Avoid extreme head movements

### Audio Requirements

* **Clear speech** - Well-recorded audio without background noise
* Set `start_seconds` and `end_seconds` to select the clip and provide enough audio for that segment.
* **Supported formats** - MP3, WAV, AAC, FLAC, M4A, OPUS, OGG/OGA, WEBM/WEBA, AIFF, AMR
* **Natural pacing** - Normal speaking pace for best results

### Matching Audio to Video

| Factor            | Recommendation                               |
| :---------------- | :------------------------------------------- |
| Duration          | Audio and video should be similar length     |
| Expression        | Match emotional tone between audio and video |
| Language          | Works across languages                       |
| Multiple speakers | Best with single speaker                     |

## Code Examples

### Basic Lip Sync

<CodeGroup>
  ```python Python theme={null}
  from magic_hour import Client
  import os

  client = Client(token=os.getenv("MAGIC_HOUR_API_KEY"))

  result = client.v1.lip_sync.generate(
      assets={
          "audio_file_path": "https://raw.githubusercontent.com/runshouse/Sample_Assets/main/you-are-just-a-line-of-code.mp3",
          "video_file_path": "https://raw.githubusercontent.com/runshouse/Sample_Assets/main/sideeyegirl.mp4",
          "video_source": "file"
      },
      end_seconds=2,
      start_seconds=0,
      max_fps_limit=30,
      style={
          "generation_mode": "lite"
      },
      name="Side Eye Girl Code Lip Sync",
      wait_for_completion=True,
      download_outputs=True,
      download_directory="."
  )

  if result.status == "complete":
      print(f"✅ Lip sync complete!")
      print(f"Downloaded to: {result.downloaded_paths}")
      print(f"Credits charged: {result.credits_charged}")
  else:
      print(f"Job ended with status: {result.status}")
      if result.error:
          print(f"Error: {result.error.message}")
  ```

  ```javascript Node.js theme={null}
  import { Client } from "magic-hour";

  const client = new Client({ token: process.env.MAGIC_HOUR_API_KEY });

  const result = await client.v1.lipSync.generate(
    {
      assets: {
        audioFilePath:
          "https://raw.githubusercontent.com/runshouse/Sample_Assets/main/you-are-just-a-line-of-code.mp3",
        videoFilePath:
          "https://raw.githubusercontent.com/runshouse/Sample_Assets/main/obamamicdrop.mov",
        videoSource: "file",
      },
      endSeconds: 2,
      startSeconds: 0,
      maxFpsLimit: 30,
      style: {
        generationMode: "lite",
      },
      name: "Obama Code Lip Sync",
    },
    {
      waitForCompletion: true,
      downloadOutputs: true,
      downloadDirectory: ".",
    }
  );

  if (result.status === "complete") {
    console.log(`✅ Lip sync complete!`);
    console.log(`Downloaded to: ${result.downloadedPaths}`);
  } else {
    console.error(`Job ended with status: ${result.status}`);
    if (result.error) console.error(result.error.message);
  }
  ```
</CodeGroup>

## Pricing

Lip Sync is charged per rendered frame, and the rate depends on `style.generation_mode`:

| Generation mode | Credits per frame | Notes                                 |
| :-------------- | :---------------- | :------------------------------------ |
| `lite`          | 1                 | Available on all tiers                |
| `standard`      | 1                 | Creator, Pro, and Business tiers only |
| `pro`           | 2                 | Creator, Pro, and Business tiers only |

For example, a 10-second clip capped at 30 FPS in `lite` mode costs about 300 credits. Use `max_fps_limit` to lower the frame rate and reduce cost. Credits are only charged for the frames that actually render, and the completed job's `credits_charged` shows the exact cost.

<Tip>
  **Try this in our Google Colab Cookbook:** [Run this API with sample
  code](https://colab.research.google.com/drive/1NTHL_lr_s-qBJ-mSecSXPzRLi9_V5JiU?usp=sharing). Just
  add your API key.
</Tip>

## API Reference

<Card title="Lip Sync API Reference" icon="webhook" href="/api-reference/video-projects/lip-sync">
  View full API specification
</Card>

## Related Tools

<CardGroup cols={2}>
  <Card title="AI Voice Generator" icon="microphone" href="/tools/audio/voice-generator">
    Generate speech audio for your videos
  </Card>

  <Card title="Face Swap Video" icon="user" href="/tools/video/face-swap-video">
    Replace faces in videos
  </Card>
</CardGroup>
