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

# Generate Video with Audio

> Create AI-generated videos with synchronized sound, effects, and speech

This guide shows you how to generate an AI video that includes audio. With a single boolean field, the model produces synchronized ambient sound, effects, and any speech implied by your prompt, so the clip is ready to use without a separate audio pass.

## What You Will Build

> [card] Synchronized Sound
>
> Ambient audio and effects that match the action on screen

> [card] Spoken Lines
>
> Dialogue or narration described in the prompt, voiced by the model

> [card] One Request
>
> Audio is generated together with the video, in the same job

> [card] Predictable Cost
>
> A fixed with-audio rate per second, shown before you generate

## Before You Begin

Make sure you have:

* A [Pictory API key](https://app.pictory.ai/api-access)
* Node.js or Python installed on your machine
* The required packages installed

```bash npm theme={null}
npm install axios
```

```bash pip theme={null}
pip install requests
```

## Which Models Support Audio

| Model | Audio | AI Credits per Second (with audio) |
| - | - | - |
| `pixverse6` | Optional | 5.55 |
| `pixverse5.6` | Optional | 3.15 |
| `veo3.1` | Optional | 60 |
| `omni-flash` | Always on | 19.5 |

> [!NOTE]
>
> `omni-flash` always produces audio. You do not need to send `audio: true` for it, and `audio: false` is rejected with a `400` validation error. Every other model generates a silent video unless you set `audio: true`.

## Step-by-Step Guide

### Step 1: Set Up Your Request

Add `audio: true` to an otherwise ordinary video request. Describe the sounds you expect in the prompt: the model uses the description to decide what to voice.

```javascript Node.js theme={null}
import axios from "axios";

const API_BASE_URL = "https://api.pictory.ai/pictoryapis";
const API_KEY = "YOUR_API_KEY"; // Replace with your actual API key

// Video generation with audio
const videoRequest = {
  prompt: "Waves crash against a rocky shore at dusk while seagulls call overhead, wide shot with slow push-in",
  model: "pixverse6",
  aspectRatio: "16:9",
  duration: "8s",
  audio: true
};
```

```python Python theme={null}
import requests
import time

API_BASE_URL = "https://api.pictory.ai/pictoryapis"
API_KEY = "YOUR_API_KEY"  # Replace with your actual API key

# Video generation with audio
video_request = {
    "prompt": "Waves crash against a rocky shore at dusk while seagulls call overhead, wide shot with slow push-in",
    "model": "pixverse6",
    "aspectRatio": "16:9",
    "duration": "8s",
    "audio": True
}
```

> [!NOTE]
>
> `audio` can be combined with every other option on the endpoint: reference images, a first frame, a first and end frame transition, or a video to extend. When extending on `veo3.1`, audio applies to the new segment.

### Step 2: Submit the Video Generation Request

Send the request to the AI Studio video generation endpoint.

```javascript Node.js theme={null}
async function generateVideoWithAudio() {
  try {
    console.log("Submitting video generation request with audio...");

    const response = await axios.post(
      `${API_BASE_URL}/v1/aistudio/videos`,
      videoRequest,
      {
        headers: {
          "Content-Type": "application/json",
          Authorization: API_KEY,
        },
      }
    );

    const jobId = response.data.data.jobId;
    console.log("Video generation started.");
    console.log("Job ID:", jobId);

    return jobId;
  } catch (error) {
    console.error("Error submitting request:", error.response?.data || error.message);
    throw error;
  }
}
```

```python Python theme={null}
def generate_video_with_audio():
    try:
        print("Submitting video generation request with audio...")

        response = requests.post(
            f"{API_BASE_URL}/v1/aistudio/videos",
            json=video_request,
            headers={
                "Content-Type": "application/json",
                "Authorization": API_KEY
            }
        )
        response.raise_for_status()

        job_id = response.json()["data"]["jobId"]
        print("Video generation started.")
        print(f"Job ID: {job_id}")

        return job_id

    except requests.exceptions.RequestException as error:
        print(f"Error submitting request: {error}")
        raise
```

### Step 3: Poll for the Result

Check the job status at regular intervals until the video is ready. The completed response is the same as for a silent video; the audio track is inside the delivered MP4.

```javascript Node.js theme={null}
async function waitForVideo(jobId) {
  console.log("\nPolling for video generation result...");

  while (true) {
    const response = await axios.get(
      `${API_BASE_URL}/v1/jobs/${jobId}`,
      {
        headers: { Authorization: API_KEY },
      }
    );

    const data = response.data;
    const status = data.data.status;
    console.log("Status:", status);

    if (status === "completed") {
      console.log("\nVideo generated successfully!");
      console.log("Video URL:", data.data.url);
      console.log("Duration:", data.data.duration);
      console.log("AI Credits Used:", data.data.aiCreditsUsed);
      return data;
    }

    if (status === "failed") {
      throw new Error("Video generation failed: " + JSON.stringify(data));
    }

    // Wait 15 seconds before polling again
    await new Promise(resolve => setTimeout(resolve, 15000));
  }
}

// Run the complete workflow
generateVideoWithAudio()
  .then(jobId => waitForVideo(jobId))
  .then(result => console.log("\nDone!"))
  .catch(error => console.error("Error:", error));
```

```python Python theme={null}
def wait_for_video(job_id):
    print("\nPolling for video generation result...")

    while True:
        response = requests.get(
            f"{API_BASE_URL}/v1/jobs/{job_id}",
            headers={"Authorization": API_KEY}
        )
        response.raise_for_status()

        data = response.json()
        status = data["data"]["status"]
        print(f"Status: {status}")

        if status == "completed":
            print("\nVideo generated successfully!")
            print(f"Video URL: {data['data']['url']}")
            print(f"Duration: {data['data']['duration']}")
            print(f"AI Credits Used: {data['data']['aiCreditsUsed']}")
            return data

        if status == "failed":
            raise Exception(f"Video generation failed: {data}")

        # Wait 15 seconds before polling again
        time.sleep(15)

# Run the complete workflow
if __name__ == "__main__":
    job_id = generate_video_with_audio()
    result = wait_for_video(job_id)
    print("\nDone!")
```

## Understanding the Parameters

| Parameter | Type | Required | Default | Description |
| - | - | - | - | - |
| `prompt` | string | Yes | - | A descriptive text of the video to generate, including the sounds you expect. Must be between 5 and 5,000 characters. |
| `audio` | boolean | No | `false` (`true` on `omni-flash`) | Generate synchronized audio with the video. Rejected on models without audio support. |
| `model` | string | No | `pixverse5.6` | The AI model to use for generation. Supported values: `pixverse6`, `pixverse5.6`, `veo3.1`, `omni-flash`. See [Generate Video API](https://docs.pictory.ai/api-reference/ai-studio/generate-video.md) for model capabilities and pricing. |
| `aspectRatio` | string | No | First supported ratio of the selected model | The output aspect ratio. Valid values depend on the model. |
| `duration` | string | No | First supported duration of the selected model | The video length. Valid values depend on the model. |
| `trainingPreset` | string | No | - | `sales-training`, `product-training`, or `soft-skills-training`. Steers prompt enhancement and always turns it on, even when `enhancePrompt` is `false`. |
| `enhancePrompt` | boolean | No | `false` | Set to `true` to rewrite the prompt with the AI enhancer before generation. Off by default: the prompt is sent verbatim. |
| `webhook` | string | No | - | A URL to receive a POST notification when the job completes. Must be a valid URI. |

## How Audio Is Billed

Audio is not a surcharge on top of the silent rate; it is a separate per-second rate for the model. A `8s` video on `pixverse6` costs 32.4 credits without audio and 44.4 credits with audio. Credits are reserved when the job is created and released if the generation fails. The `aiCreditsUsed` field on the completed job shows the final charge.

## Tips for Video with Audio

* **Describe the soundscape.** Mention the sounds you want ("rain on a tin roof", "a crowd cheering") as well as the visuals. The model voices what the prompt describes.
* **Quote the dialogue.** For speech, put the exact words in the prompt, for example: a barista says "Your coffee is ready."
* **Keep clips self-contained.** Audio is generated per job, so when you build multi-segment videos, describe a natural sound at the end of one segment and the start of the next to avoid abrupt cuts.
* **Check the listing.** Videos returned by [Get Generated Videos](https://docs.pictory.ai/api-reference/ai-studio/get-videos.md) carry an `audio` flag so you can tell silent and sound clips apart later.

## Next Steps

* [Generate Video from Text Prompt](https://docs.pictory.ai/guides/ai-studio/text-to-video.md) for the basic video workflow
* [Generate Video from Reference Images](https://docs.pictory.ai/guides/ai-studio/video-from-reference-images.md) to keep subjects consistent
* [Extend Video with AI](https://docs.pictory.ai/guides/ai-studio/extend-video.md) to continue an existing video
* [Generate Video API Reference](https://docs.pictory.ai/api-reference/ai-studio/generate-video.md) for the complete parameter documentation


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.