Discussions

Ask a Question
Back to All

Create a Video Avatar using Audiofile returns unknown error

Hello,

At the moment, we are using a trial of the OpenAI API and are experimenting with various functionalities. Our goal is to create an audio file using ElevenLabs’ API, as their sound model offers a more natural quality. We’ve successfully managed the following:

Listing all available avatars: We’ve retrieved and filtered the available avatars.
Selecting the appropriate avatar: The chosen avatar is identified and set.
Uploading the audio: We successfully upload the generated audio.mp3 file to the HeyGen server using their API.
However, when we attempt to generate a video, we encounter an unknown error. The error message isn’t descriptive; in the web interface, the videos we want to generate appear, but each one has a small red error message in the bottom left corner without further explanation. We’ve tried various parameters, including setting the resolution to 1280x720 (as we’re in FreeMode), but without success. I also attempted troubleshooting with ChatGPT, but we were unable to identify the root of the issue, because after 5 tries we are over our daily limit...

It seems that everything is in place, but we may be missing a parameter or configuration detail that’s preventing successful video generation.

Here is my function:

def generate_video_with_audio_asset(
avatar_id: str,
audio_asset_id: str,
title: str = "Generated Video",
caption: bool = False,
callback_id: str = None,
avatar_style: str = "normal",
scale: float = 1.0,
offset_x: float = 0.0,
offset_y: float = 0.0,
matting: bool = False,
background_type: str = "color",
background_value: str = "#008000"
):
url = "https://api.heygen.com/v2/video/generate"
payload = {
"title": title,
"test": True, #Wasserzeichen an/aus
"caption": caption,
"callback_id": callback_id,
"video_inputs": [
{
"character": {
"type": "avatar",
"avatar_id": avatar_id,
"scale": scale,
"avatar_style": avatar_style,
"offset": {"x": offset_x, "y": offset_y},
"matting": matting
},
"voice": {
"type": "audio",
"audio_asset_id": audio_asset_id
},
"background": {
"type": background_type,
"value": background_value
}
}
],
"dimension": {
"width": 1280,
"height": 720
},
"aspect_ratio": "16:9"
}

headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "x-api-key": HEYGEN_API_KEY
}

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

print(f"API Antwort: {data}")  # Debug

# Get video_id
video_id = data.get("data", {}).get("video_id")

if response.status_code == 200 and video_id:
    print(f"Video-GENERIERUNG gestartet mit ID: {video_id}")
    return video_id
else:
    error_message = data.get("error", {}).get("message", "Unbekannter Fehler")
    print(f"Fehler bei der Videogenerierung: {error_message}")
    return None

Thanks for the help, best regards from germany!