Quick start

Welcome to the DupDub API Video Translation feature, a powerful tool designed to seamlessly translate and localize your video content for global audiences. This guide will walk you through the quick and easy steps to get started with our video translation service. Whether you’re aiming to reach new markets or making your content accessible to a wider audience, DupDub’s API provides an efficient solution to translate videos between various languages with high accuracy and speed.

 

Our API leverages advanced AI technologies to ensure your video content is translated with contextual accuracy, maintaining the original tone and intent. By following this guide, you’ll learn how to create a video translation project, submit your video for translation, and retrieve the translated video, all through simple API calls.

 

Let’s get started by setting up your first video translation project.

Step 1: Create a Video Translation Project

To kick off, you’ll need to create a new video translation project. This step involves specifying the video URL, source language, target language, and providing a title for your project. By doing so, you initiate the translation process and prepare your content for a global audience. Here’s how to proceed:

 

  1. Define Project Details: Prepare the video URL, the source language, the target language, and a descriptive title for your project.

  2. Submit the Translation Request: Use the provided DupDub API endpoint to submit your video translation project. Ensure you include all required details in your request.
import requests

# API endpoint for creating a video translation project
url = "https://moyin-gateway.dupdub.com/tts/v1/videoTrans/create"

# Your API key
api_key = "your_api_key_here"

# Project details
data = {
  "videoUrl": "https://cdn-static.dupdub.com/backend/subtitles/2024-03-08-9220709806353611459.mp4",
  "sourceLanguage": "English",
  "targetLanguage": "German",
  "title": "Did Mona Lisa Find The Pearl Earring?",
  "speakerNum": -1,
  "transText": 2,
  "lipSync": 2
}

headers = {
    "dupdub_token": f"{api_key}",
    "Content-Type": "application/json"
}

response = requests.post(url, json=data, headers=headers)

# Parse the response
if response.status_code == 200:
    result = response.json()
    print(result)
    task_id = result["data"]["taskId"]
    print("Project created successfully. Task ID:", task_id)
else:
    print("Failed to create project. Status Code:", response.status_code)

Note: It’s crucial to store the task_id you receive in the response. This identifier is essential for querying the progress of your translation task in the subsequent steps.

Step 2: Query Translation Progress

After initiating your video translation project, the next step is to monitor its progress. Since translation time can vary, it typically takes about 1.5 times the length of the original video to complete. Here’s how to keep track of your translation task:

  1. Monitor Progress: Use the task_id you obtained from Step 1 to periodically check the status of your translation. This will inform you when your translation is completed and ready for download.
import requests

# API endpoint for quering the translation progress
url = "https://moyin-gateway.dupdub.com/tts/v1/videoTrans/batchQryTask"

# Your API key
api_key = "your_api_key_here"

# Request Payload
data ={
  "taskId": [
    "bb59f4e20de140b29c60142120d143b2"
  ]
}

headers = {
    "dupdub_token": f"{api_key}",
    "Content-Type": "application/json"
}

response = requests.post(url, json=data, headers=headers)

# Parse the response
if response.status_code == 200:
    status_result = response.json()
    print(status_result)
    if status_result["data"][0]["statusPercentage"] == 100:
        print("Translation completed. Download URL:", status_result["data"][0]["retVideoUrl"])
    else:
        print("Translation in progress. Current status:", status_result["data"][0]["statusPercentageName"])
else:
    print("Failed to query project status. Status Code:", response.status_code)

Implement a polling mechanism in your application to automate this process, checking the translation status at intervals that make sense for your workflow. Adjust the frequency of these checks based on your application’s requirements and the expected video lengths you are working with.

 

Best Practices and Tips

  • Robust Error Handling: Ensure your implementation can gracefully handle API errors or unexpected responses. This includes checking for HTTP status codes and parsing error messages returned by the API.
  • Manage API Rate Limits: Be aware of and adhere to the API’s rate limits. Design your application to gracefully handle rate limit errors, possibly by implementing retry logic with exponential backoff.
  • User Feedback: Keep your users informed about the status of their video translation tasks, especially if they are processing longer videos. Providing progress updates can greatly improve user experience.

 

Conclusion

By following these steps and integrating the recommended best practices, you’ll be able to effectively use the DupDub API Video Translation feature in your application. This Quick Start Guide is designed to help developers swiftly navigate through the process of translating video content, making it easier to globalize and localize video assets for a wider audience. If you encounter any issues or have further questions, our support team is ready to assist you.

Table of Contents