Prerequisites

  • You have an API key. If not, you can get one by contacting us.
  • You have python installed on your machine along with the requests library

Step 1 (Optional): Create a video resource

If you have an existing video you want to use as a reference, follow this step. This is where your face, expressions and voice are taken from. If the file is larger than 5MB, follow the Upload Large Resources guide and note the resource_id. If not, you can upload it directly.

Step 2: Create a script to personalize the video

Python
files = {
    "file": (
        "text.txt",
        bytes(
            "Hey Pranav, how do you make videos at Verbalia today?",
            "utf-8",
        ),
        "text/plain",
    )
}
# If you want to load a txt file from disk, comment out the above lines
# and uncomment the below line
# files = {'file': ('text.txt', open('text.txt', 'rb'), 'text/plain')}

data = {
    "resource_name": "pranav-text",  # Descriptive name
    "resource_type": "text",  # One of the 5 types
}

# Make the POST request
script_response = requests.post(
    base_url + "/resources/upload", files=files, params=data, headers=headers
)

# Check the response
if script_response.status_code != 200:
    print(f"Failed to upload file. Status code: {script_response.status_code}")
    print("Response:", script_response.text)
    sys.exit(1)
print("Upload successful", script_response.json())
# Contains resource_id which should be noted

Step 3: Create a generation request body

This is just a regular generation, but the way you use your own face, expressions and voice is by providing your reference video’s resource_id for the face and voice.

Python
# Create a generation request body
body = {
    "avatar": {
        "face": "resource-video-qV1ApL",  # From step 1
        "voice": "resource-video-qV1ApL",  # From step 1
    },
    "script": {
        "resource_id": "resource-text-5qyAQV", # From step 2
        "type": "text"
    },
    "output": {
        "resolution": "512"
    },
}

generation_response = requests.post(
    base_url + "/generate-video", json=body, headers=headers
)

Step 4: Poll for the status and download the video

Python
while True:
    time.sleep(60)  # Poll every 60 seconds
    response = requests.get(
        base_url + "/status/" + generation_response.json()["request_id"],
        headers=headers,
    )
    print(response.json())  # Status and video urls once completed
    if response.json()["status"] not in ["pending", "processing"]:
        break

if response.json()["status"] == "completed":
    video_response = requests.get(response.json()["video_url"])
    with open("verbalia_personalize.mp4", "wb") as f:
        f.write(video_response.content)

    print("Downloaded video to verbalia_personalize.mp4")

To personalize to multiple audiences, repeat steps 2-4 with different scripts.