Replace Audio in Template
Replace audio tracks in your video templates using the Template API
Welcome to Audio Replacement!
In this guide, we will learn how to replace audio within a template and generate a video. The Template API allows you to dynamically modify audio elements to create customized videos that suit your specific needs.
Audio Properties
When replacing audio in templates, you can use the following properties to customize the audio:
- url: URL for the audio file.
- asset_id: Asset ID.
Creating Template through the Interface
To create templates, visit the Template page and click on "Create Template".
Variable Assignment:
You can use the "API Variable" menu to assign a variable to a sound element in your timeline.
Audio Script:
You can also assign a variable to your audio script. To do this, select your audio with 'Upload Audio' in the Script section, then assign a variable with the 'API Variable' menu.
Step 1: Get a List of Your Templates
Using the following API request you will get a list of your templates that you have created in the interface, obtain your template_id from here.
curl --location 'https://api.konpro.ai/v1/templates' \
--header 'accept: application/json' \
--header 'x-api-key: <your-api-key>'Step 2: Retrieve Template Elements
To retrieve template elements, use this API request. Get the variable you want to change from here.
curl --location 'https://api.konpro.ai/v1/template/<template_id>' \
--header 'accept: application/json' \
--header 'x-api-key: <your-api-key>'Step 3: Modify Template Elements and Generate Video
To modify template elements and generate videos, you need to submit an API request as follows. In the request body, specify the elements you want to change by providing the appropriate object within the variables section.
curl --location 'https://api.konpro.ai/v1/template/<template_id>/generate' \
--header 'x-api-key: <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"caption": false,
"title": "New Video",
"variables": {
"bg_music": {
"name": "bg_music",
"type": "audio",
"properties": {
"url": "<url>",
"asset_id": null
}
},
"my_script": {
"name": "my_script",
"type": "audio",
"properties": {
"url": null,
"asset_id": "<asset_id>"
}
}
}
}'You will receive a video_id after your request. To check the video's status and retrieve further details, you can use the video_status API endpoint.
Template Scene Guidelines
As for background audio, each audio must at least align with and contain one scene. Basically, scenes scale with contained script, background audios scale with contained scenes, and all visual elements (linearly) scale with whichever scene they are in. Here are some examples:
Important:
Failure to follow these guidelines will result in an "Start/End of audio 1 does not align with scene" error.