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: Create a text resource

Once uploaded, you can reuse the same resource for multiple generation requests.

Our text-to-speech backend is powered by ElevenLabs and we support all the same prompts like <break time="1.5s" />. Check out their documentation to see all the available options.

Python
import sys
import requests
import time

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}

files = {
  'file': ('text.txt', bytes('Welcome to Verbalia\'s workshop...', 'utf-8'), 'text/plain')
}

data = {
    'resource_name': 'workshop-content', # Descriptive name
    'resource_type': 'text' # One of the 5 types
}

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

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

Step 2: Submit a generation request

Python
# Create a generation request body
body = {
    "avatar": {
        "name": "adam", # One of the default avatars
    },
    "script": {
        "resource_id": text_upload_response.json()['resource_id'],
        "type": "text"
    },
}

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

# Check the response and status code
if generation_response.status_code != 200:
    print(f'Failed to generate video. Status code: {generation_response.status_code}')
    print('Response:', generation_response.text)
    sys.exit(1)
print('Generation successful.', generation_response.json())
# Contains request_id

Step 3: Poll for the status and download the video

Space out polling requests by at least 30s to avoid getting rate limited.

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"] in ["completed", "failed"]:
        break

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