> ## 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 Tool - Magic Hour Docs

> Synchronize lip movements in videos with new audio tracks.

export const ToolSection = ({type = "image", outputs = [], title = "", productSlug = "", apiSlug = ""}) => <>
    {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} />}
            </Frame>
          </Tab>)}
      </Tabs>}

    <CardGroup cols={2}>
      <Card title="API Spec" icon="webhook" horizontal href={`/api-reference/${type}-projects/${apiSlug}`}>
        See API details
      </Card>
      <Card title="Product Page" icon="video" horizontal href={`https://magichour.ai/products/${productSlug}`}>
        Learn more about {title}
      </Card>
    </CardGroup>

  </>;

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

<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

* **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
* **Appropriate length** - Audio duration determines output length
* **Supported formats** - MP3, WAV, AAC, FLAC
* **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 failed with status: {result.status}")
      if hasattr(result, 'error_message'):
          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: 8,
    style: {
      generationMode: "lite",
    },
    name: "Obama Code Lip Sync",
    waitForCompletion: true,
    downloadOutputs: true,
    downloadDirectory: ".",
  });

  console.log(`✅ Lip sync complete!`);
  console.log(`Status: ${result.status}`);
  console.log(`Downloaded to: ${result.downloadedPaths}`);
  ```
</CodeGroup>

## Pricing

Lip Sync uses credits based on video duration:

| Duration   | Approximate Credits |
| :--------- | :------------------ |
| 5 seconds  | \~150 credits       |
| 10 seconds | \~300 credits       |

<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 audio with celebrity voices
  </Card>

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