# Replace Text/Voice in Template

Modify script text and voice in templates using HeyGen's API

In this guide, we will learn how to replace **script text and voice** within a template and generate a video.

### Text Properties:

* **content:** Text content.

### Voice Properties:

* **voice\_id:** Supports any ID returned from <Anchor label="List All Voices (V2)" target="_blank" href="ref:list-voices-v2">List All Voices (V2)</Anchor> endpoint.

# Creating Template through the Interface

To create a new template:

1. Go to the HeyGen Dashboard and open the [Templates](https://app.heygen.com/templates) tab.
2. Click **Create Template**. This opens the template editor.
3. In the scene area, click the text field labeled *“Type your script or use '/' for commands”*.
4. Enter your script directly in this field.
5. To make your script dynamic, insert a placeholder variable using double curly brackets `{{}}`.
6. To assign a variable to the voice of the script, click the three-dot (⋯) menu next to the script line and select **API Variable** to create a variable.

In this example, we currently have one script in the scene. We’ll update it by replacing the existing script text with a variable.

<Image border={false} src="https://files.readme.io/b466cf2449ae2a299907de7eb0f6f32dbbab62e3d184d8cfaa6ff1e9aceab500-text_voice-modified.png" />

The current voice for `script_en`  is *Tony (American - English)* in this guide we will replace it with *Fable (Multilingual)*.

<Image border={false} src="https://files.readme.io/78d50a5f0ffeeb8570f83081cdd13f057c8dae5d2799eee6bcb21f18aa918b68-text_voice_2-modified.png" />

# Get a List of Your Templates

For instructions on listing your templates that you have created in the HeyGen interface and retrieving the `template_id`, see [Get a List of Templates](https://movio-api.readme.io/docs/generate-video-from-template-v3#get-a-list-of-your-templates).

# Retrieve Template Elements

To retrieve template elements you will need to submit an API request as follows. In the response, you’ll receive details of all variables defined in the template, in this case, the voice and text element details, which can later be modified when creating videos.

```bash Request
curl --request GET \
     --url https://api.heygen.com/v3/template/<template_id> \
     --header 'accept: application/json' \
     --header 'x-api-key: <your-api-key>'

```

```json Response
{
  "error": null,
  "data": {
    "version": "4",
    "variables": {
      "script1_voice": {
        "name": "script1_voice",
        "type": "voice",
        "properties": {
          "voice_id": "1ae3be1e24894ccabdb4d8139399f721"
        }
      },
      "script_en": {
        "name": "script_en",
        "type": "text",
        "properties": {
          "content": ""
        }
      }
    },
    "scenes": [
      {
        "id": "7aqMaMmz",
        "script": "{{script_en}}",
        "variables": [
          {
            "name": "script_en",
            "type": "text"
          },
          {
            "name": "script1_voice",
            "type": "voice"
          }
        ]
      }
    ]
  }
}


```

For a full list of parameters and complete response details, see detailed API Reference: [Retrieve Template Details (V3)](https://movio-api.readme.io/reference/get-template-v3).

# Voices

For the target `voice_id` you can choose any id returned from the [List All Voices (V2)](https://movio-api.readme.io/reference/list-voices-v2)  endpoint. In this guide, we will utilize *Fable (Multilingual)*.

```curl Request
curl --location 'https://api.heygen.com/v2/voices' \
     --header 'accept: application/json' \
     --header 'x-api-key: <your-api-key>'
```

```json Response
...
{
  "voice_id": "8b92884579014f8e8147836bbd0c13ca",
  "language": "Multilingual",
  "gender": "male",
  "name": "Fable",
  "preview_audio": "https://static.heygen.ai/voice_preview/3ii9BykcfMVv2kTCZUm9mf.wav",
  "support_pause": false
}
...
```

For the complete list of available voices, including their IDs, supported languages, and preview audio links, see detailed API Reference : [List All Voices (V2)](https://movio-api.readme.io/reference/list-voices-v2)

# Modify Template Elements and Generate Video

To change template elements and generate videos, you will need to submit an API request as follows. In the request body, *specify the elements you want to modify* by providing the appropriate object within the *variables* section.

```bash Request
curl --location 'https://api.heygen.com/v2/template/<template_id>/generate' \
     --header 'X-Api-Key: <your-api-key>' \
     --header 'Content-Type: application/json' \
     --data '{
  "caption": false,
  "title": "New Video",
  "variables": {
    "script_en": {
      "name": "script_en",
      "type": "text",
      "properties": {
        "content": "Hey there, how are you today?"
      }
    },
    "script1_voice": {
      "name": "script1_voice",
      "type": "voice",
      "properties": {
        "voice_id": "8b92884579014f8e8147836bbd0c13ca"
      }
    }
  }
}'
```

```json Response
{
  "error": null,
  "data": {
    "video_id": "<video_id>"
  }
}
```

To explore how different variable types can be modified when generating a new video, see detailed API Reference: [Generate Video from Template](https://movio-api.readme.io/reference/generate-from-template-v2)

You will receive a `video_id` after your request. To check the video's status and retrieve further details, you can use the [Retrieve Video Status/Details](https://movio-api.readme.io/reference/video-status) API endpoint. You can view complete status response examples on the right-side **Response** panel of the API Reference page - open the **Examples** dropdown to view responses for different video statuses. You can select any example to preview the corresponding response body.

### Status Descriptions

**`pending`**\
The video is queued and waiting to start rendering.

**`waiting`**\
The video is in waiting state.

**`processing`**\
The video is currently rendering.

**`completed`**\
The video has successfully rendered and is ready for download.

**`failed`**\
The video could not be rendered due to an error (for example, if the duration exceeds plan limits).

<Embed url="https://app.heygen.com/embeds/ff9a371ac21c45c7894a5355790a0e12" href="https://app.heygen.com/embeds/ff9a371ac21c45c7894a5355790a0e12" typeOfEmbed="iframe" height="450px" width="100%" iframe="true" />

# Conclusion

In this guide, we've walked you through the process of *replacing voice and script text* within a template video using **HeyGen's Template API**. By following the steps outlined here, you can modify template elements to create customized videos that suit your specific needs.