Quick start

Welcome to the DupDub API Talking Photo feature, an advanced tool meticulously engineered to transform static images into captivating Talking Photos. In today’s digital landscape, visual content is more engaging than ever, and our AI avatar service offers a groundbreaking way to breathe life into your images.

 

With DupDub’s AI avatar feature, you can go beyond traditional static images and create dynamic, interactive experiences that resonate with your audience. Imagine being able to turn a simple photograph into a personalized video message, where the subjects come to life and speak directly to the viewer. Whether you’re a content creator, educator, or developer, our API empowers you to unlock new possibilities for storytelling and communication.

 

Let’s get started by setting up your first AI avatar project.

 

Step 1: Face Detection

Before creating your AI avatar, it’s essential to accurately detect faces within your images. Utilize our face detection API to identify and localize faces with precision. This step is crucial for enabling our AI avatar’s multi-speaker functionality, ensuring that each individual’s speech is accurately represented:

import requests

# API endpoint for face detection
url = "https://moyin-gateway.dupdub.com/tts/v1/photoProject/detectAvatar"

# Your API key
api_key = "<<Your DupDub API key>>"

# Portrait URL
data={
  "photoUrl": "https://cdn-static.dupdub.com/backend/subtitles/72d1ad2af8734b21ab134b9a7f538075.png"
}

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)
else:
    print("Failed to detect face. Status Code:", response.status_code)

Step 2: Create an AI Avatar Project

Once you’ve identified the faces in your image, it’s time to create your AI avatar project. Submit the image URL, audio URL, and face bounding box coordinates to our API. Our robust system will efficiently process your inputs, leveraging advanced algorithms to synthesize lifelike avatars that accurately mimic the speech of the individuals depicted.

import requests

# API endpoint for creating a AI avatar project
url = "https://moyin-gateway.dupdub.com/tts/v1/photoProject/createMulti"

# Your API key
api_key = "<<Your DupDub API Key>>"

# Request Payload
data={
  "photoUrl": "https://cdn-static.dupdub.com/backend/subtitles/72d1ad2af8734b21ab134b9a7f538075.png",
  "info": [
    {
      "audioUrl": "https://objectstorage.us-ashburn-1.oraclecloud.com/n/cnqva8xzkaqv/b/oci-useast-backend-public/o/transfromWav/audio/adee320c694c4ab58cb42e6c74f85426.wav",
      "box": [
        403,
        185,
        755,
        662
      ]
    }
  ],
  "watermark": 0,
  "useSr": False
}

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)
else:
    print("Failed to create project. Status Code:", response.status_code)

Step 3: Monitor Task Progress

After initiating your AI avatar project, it’s important to stay informed about its progress. Avatar creation time can vary depending on factors such as image complexity and audio duration. By querying the task progress, you can track the status of your project and ensure timely completion.


import requests

# API endpoint for query the AI avatar project status
url = "https://moyin-gateway.dupdub.com/tts/v1/photoProject/348268"

# Your API key
api_key = "<<Your DupDub API Key>>"

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

response = requests.get(url, headers=headers)

# Parse the response
if response.status_code == 200:
    result = response.json()
    print(result)
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 project status at intervals that make sense for your workflow. Adjust the frequency of these checks based on your application’s requirements and the audio 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

With these simple steps and best practices, you’re now equipped to leverage the full potential of DupDub’s AI avatar feature. Whether you’re creating personalized video messages, enhancing educational content, or adding a touch of interactivity to your applications, our API empowers you to bring your ideas to life with ease.

Start creating captivating Talking Photos today with DupDub API!

Table of Contents