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

# Auto Subtitle Generator API

> Automatically generate and embed subtitles in videos with AI-powered transcription.

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

Auto Subtitle Generator transcribes speech and embeds captions in the video. Use a preset or custom formatting to style them.

<ToolSection
  title="Auto Subtitle Generator"
  productSlug="auto-subtitle-generator"
  apiSlug="auto-subtitle-generator"
  type="video"
  outputs={[
{
  src: "/get-started/images/autosubtitlegeneratorexample1.mp4",
},
{
  src: "/get-started/images/autosubtitlegeneratorexample2.mp4",
},
]}
/>

## How It Works

1. **Upload video** - Provide a video with spoken content
2. The API transcribes the speech.
3. **Subtitles generated** - Formatted subtitles with accurate timing
4. **Download video** - Retrieve video with embedded subtitles

## Use Cases

* **Social media content** - Add captions for better engagement and accessibility
* **Educational videos** - Make content accessible to all learners
* **Marketing videos** - Increase view time with subtitled content
* **International content** - Transcribe videos in multiple languages
* Add captions for accessibility. Review transcription and timing before publishing.

## Best Practices

### Video Quality

<Tip>**Use clear audio** - Better audio quality produces more accurate transcriptions.</Tip>

* **Minimize background noise** - Clean audio improves accuracy
* **Clear speech** - Well-enunciated words transcribe better
* **Single speaker preferred** - Best results with one speaker at a time
* **Avoid music overlap** - Heavy music can interfere with transcription

### Language Support

The API has no language-selection parameter. Review generated captions for names, accents, and technical terms, and choose a font that supports your language.

### Subtitle styling

Choose `karaoke`, `cinematic`, `minimalist`, or `highlight` with `style.template`. Use `style.custom_config` to override a template. If you omit the template, custom configuration must include `font`, `text_color`, `vertical_position`, and `horizontal_position`.

## Code Examples

### Basic Auto Subtitle

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

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

  result = client.v1.auto_subtitle_generator.generate(
      assets={
          "video_file_path": "https://raw.githubusercontent.com/runshouse/Sample_Assets/main/jude_bellingham_greeting.mp4"
      },
      start_seconds=0,
      end_seconds=8,
      style={"template": "karaoke"},
      name="Subtitled Video",
      wait_for_completion=True,
      download_outputs=True,
      download_directory="."
  )

  if result.status == "complete":
      print(f"✅ Subtitles 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.autoSubtitleGenerator.generate(
    {
      assets: {
        videoFilePath:
          "https://raw.githubusercontent.com/runshouse/Sample_Assets/main/obamamicdrop.mov",
      },
      startSeconds: 0,
      endSeconds: 2,
      style: { template: "karaoke" },
      name: "Subtitled Video",
    },
    {
      waitForCompletion: true,
      downloadOutputs: true,
      downloadDirectory: ".",
    }
  );

  if (result.status === "complete") {
    console.log(`✅ Subtitles 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>

## Output Format

Retrieve the captioned video from the completed video project's `downloads` array. The API has no SRT/VTT export-format option.

## Pricing

Cost depends on the selected video segment. The create response contains an estimate in `credits_charged`; check the completed job for the final total. See [Billing](/billing/overview) for current pricing.

<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="Auto Subtitle Generator API Reference" icon="webhook" href="/api-reference/video-projects/auto-subtitle-generator">
  View full API specification
</Card>

## Related Tools

<CardGroup cols={2}>
  <Card title="Lip Sync" icon="lips" href="/tools/video/lip-sync">
    Sync audio with video lip movements
  </Card>

  <Card title="Video-to-Video" icon="film" href="/tools/video/video-to-video">
    Transform video styles and aesthetics
  </Card>
</CardGroup>
