This is the video you want to translate. 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.
# Create a translation request bodyimport sysimport requestsimport timebase_url = "https://api.verbalia.net"headers = {"X-API-Key": "<api_key>"}# Here goes the code for resource uploadbody = { "video_resource_id": response.json()["resource_id"], # Resource ID from the previous step "source_language": "en", # The language of the video "target_language": "fr", # The language to translate to}translation_response = requests.post( base_url + "/translate-video", json=body, headers=headers)# Check the response and status codeif translation_response.status_code != 200: print(f"Failed to translate video. Status code: {translation_response.status_code}") print("Response:", translation_response.text) sys.exit(1)print("Translation successful.", translation_response.json())# Contains request_id
Step 3: Poll for the status and download the video
Python
while True: time.sleep(60) # Poll every 60 seconds response = requests.get( base_url + "/status/" + translation_response.json()["request_id"], headers=headers, ) print(response.json()) # Status and video urls once completed if response.json()["status"] not in ["pending", "processing"]: breakif response.json()["status"] == "completed": video_response = requests.get(response.json()["video_url"]) with open(f"verbalia_translation.mp4", "wb") as f: f.write(video_response.content) print("Downloaded video to verbalia_translation.mp4")