Create automated news API videos with AI avatars

Advances in generative AI make it possible to automate the creation of news videos. Generative AI can create AI avatars who can substitute a real life news presenter or news anchor. Add to this the wide availability of News API's and the Shotstack video editing API and you can rapidly create personalised news videos at scale.

In this guide, we will show you how to automatically generate news videos using AI and various API's. We will use the World News API to get news article content, OpenAI's text generation API to summarise an article, Shotstack Create API to generate an avatar video, and Shotstack Edit API to combine everything in to a seamless video.

About Shotstack

Shotstack is a cloud-based video automation platform that includes API's, design and workflow tools to create and edit videos at scale. In this guide we will be using the Create API to generate the AI news avatar using D-ID and the Edit API to stitch everything together in to a video.

About D-ID

D-ID is an AI avatar service. It can generate realistic AI avatars and presenters who will narrate a body of provided text. Shotstack integrates directly with D-ID via a unified API endpoint. You will still need to register and set up a D-ID account however and provide Shotstack with an API key.

About the World News API

The World News API is a free to use API that provides news articles from around the world. Unlike many news API's, it includes the complete body of the article, for free, and not just the article URL. It also includes a headline, image, search functionality and is easy to use.

About OpenAI text generation API

The OpenAI text generation API provides similar functionality to ChatGPT. It can be used to summarise a body of text in to a shorter, more concise version. We'll use this to create our voice over for the AI news avatar.

Pre-requisites

To follow along with this guide, you will need:

With the exception of OpenAI, all the API's used in this guide are free to use, have a free trial or a free tier. OpenAI may require you to purchase $5 of credits.

Generating an AI avatar news video

The following steps will show you how to call each API to generate a news video. While we will be using cURL in this guide, it should give you an understanding of how each step could be fully automated within an application or workflow.

Fetching news from the World News API

The first step is to call the World News API to get a news article. Make sure you have registered an account, logged in to the console and retrieved the API key. We will use the search-news endpoint to find and filter an article that we are interested in. In this example we will find an article related to Tesla, the electric car company.

Call the World News API using the following cURL command. Make sure to replace NEWS_API_KEY with your API key.

curl -L 'https://api.worldnewsapi.com/search-news?language=en&source-country=us&text=tesla&earliest-publish-date=2024-06-01&news-sources=https%3A%2F%2Farstechnica.com&sort=publish-time&sort-direction=DESC' \
-H 'x-api-key: NEWS_API_KEY'

The request above sets the following parameters:

  • language to en for English language news
  • source-country to us for news from the United States
  • text to tesla to search for articles related to Tesla
  • earliest-publish-date to 2024-06-01 to search for articles published after this date
  • news-sources to https://arstechnica.com to search for articles from Ars Technica
  • sort to publish-time to sort the results by publish time
  • sort-direction to DESC to sort the results most recent first

You should receive a response similar to below, which includes an array of relevant news articles:

{
"offset": 0,
"number": 10,
"available": 7,
"news": [
{
"id": 233596680,
"title": "Breaking: Elon Musk drops claims that OpenAI abandoned mission",
"text": "While Musk has spent much of today loudly criticizing the Apple/OpenAI deal, he also sought to drop his lawsuit against OpenAI, a court filing today showed. In the filing, Musk's lawyer Morgan Chu notified the Superior Court of California in San Francisco of Musk's request for dismissal of his entire complaint without prejudice. There are currently no further details as to why Musk decided to drop the suit. Musk's lawsuit accused OpenAI CEO Sam Altman and President Greg Brockman of drifting away from its original nonprofit mission by forming a for-profit subsidiary later. It also claimed that OpenAI breached its founding agreement to make notable AI advancements freely available to the public. Musk co-founded OpenAI in 2015 and previously provided funding but is no longer with the company after leaving in 2018. \"To this day, OpenAI Inc.'s website continues to profess that its charter is to ensure that AGI ‘benefits all of humanity,'\" the lawsuit read. \"In reality, however, OpenAI Inc. has been transformed into a closed-source de facto subsidiary of the largest technology company in the world: Microsoft.\" Musk had previously requested a 10-day jury trial that sought an injunction and maximum punitive damages, but OpenAI had denied that he was entitled to any relief. \"The complaint fails to state a claim for breach of contract, as Musk cannot allege the existence of any 'Founding Agreement,'\" OpenAI had argued, calling Musk's complaint a \"fiction.\" \"He attaches no contract by that name to the complaint, and the documents he does attach contradict his allegations as to the alleged terms of the agreement,\" OpenAI argued. Musk's request for dismissal comes the day before the hearing where discovery was supposed to start in the lawsuit. OpenAI had objected to some of Musk's discovery requests for confidential information—with both sides arguing over terms of a protective order. Now, OpenAI has seemingly escaped from sharing any internal documents that it perhaps doesn't want Musk or the public to have access to. Musk has so far not posted about his request to dismiss the lawsuit on X, seemingly more focused on attacking the OpenAI/Apple deal. Previously, OpenAI had released a blog clarifying the company's relationship with Musk in light of the lawsuit. In it, OpenAI shared emails between its execs and Musk, while confirming that Musk had suggested that OpenAI should “attach to Tesla as its cash cow.\" On X, Musk threatened to ban Apple devices at Tesla and his other companies over the deal, which some users interpreted as Musk being jealous of the OpenAI deal.",
"summary": "Musk previously hoped a jury would award maximum punitive damages.",
"url": "https://arstechnica.com/tech-policy/2024/06/breaking-elon-musk-drops-claims-that-openai-abandoned-mission/",
"image": "https://cdn.arstechnica.net/wp-content/uploads/2024/06/GettyImages-2148557371-760x380.jpg",
"video": null,
"publish_date": "2024-06-11 21:51:49",
"author": "Ashley Belanger",
"authors": [
"Ashley Belanger"
],
"language": "en",
"source_country": "US",
"sentiment": -0.2
}
...
]
}

Each item in the array includes a title, text and image which we will use in the steps that follow. For the purpose of this guide we will just use the first item in the array titled "Breaking: Elon Musk drops claims that OpenAI abandoned mission".

Summarising the news article with OpenAI text generation API

The article text returned in the response is quite long and not written as a voice over. We will use the OpenAI ChatGPT API to summarise the article in to a shorter, more concise version that can be used as a voice over for the AI avatar.

Make sure you have registered an account with OpenAI and retrieved the API key. We will use the text generation API to generate the summary.

Below is an example cURL request and prompt you can use to generate the summary. The prompt includes the text body of the article from the World News API. Replace OPENAI_API_KEY with your OpenAI API key.

curl -L 'https://api.openai.com/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer OPENAI_API_KEY' \
-d '{
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": "Create a short 25 second summary from the following news article that will be read by a news anchor: While Musk has spent much of today loudly criticizing the Apple/OpenAI deal, he also sought to drop his lawsuit against OpenAI, a court filing today showed. In the filing, Musk'
s lawyer Morgan Chu notified the Superior Court of California in San Francisco of Musk's request for dismissal of his entire complaint without prejudice. There are currently no further details as to why Musk decided to drop the suit. Musk's lawsuit accused OpenAI CEO Sam Altman and President Greg Brockman of drifting away from its original nonprofit mission by forming a for-profit subsidiary later. It also claimed that OpenAI breached its founding agreement to make notable AI advancements freely available to the public. Musk co-founded OpenAI in 2015 and previously provided funding but is no longer with the company after leaving in 2018. \"To this day, OpenAI Inc.'s website continues to profess that its charter is to ensure that AGI ‘benefits all of humanity,'\" the lawsuit read. \"In reality, however, OpenAI Inc. has been transformed into a closed-source de facto subsidiary of the largest technology company in the world: Microsoft.\" Musk had previously requested a 10-day jury trial that sought an injunction and maximum punitive damages, but OpenAI had denied that he was entitled to any relief. \"The complaint fails to state a claim for breach of contract, as Musk cannot allege the existence of any 'Founding Agreement,'\" OpenAI had argued, calling Musk's complaint a \"fiction.\" \"He attaches no contract by that name to the complaint, and the documents he does attach contradict his allegations as to the alleged terms of the agreement,\" OpenAI argued. Musk's request for dismissal comes the day before the hearing where discovery was supposed to start in the lawsuit. OpenAI had objected to some of Musk's discovery requests for confidential information—with both sides arguing over terms of a protective order. Now, OpenAI has seemingly escaped from sharing any internal documents that it perhaps doesn't want Musk or the public to have access to. Musk has so far not posted about his request to dismiss the lawsuit on X, seemingly more focused on attacking the OpenAI/Apple deal. Previously, OpenAI had released a blog clarifying the company's relationship with Musk in light of the lawsuit. In it, OpenAI shared emails between its execs and Musk, while confirming that Musk had suggested that OpenAI should “attach to Tesla as its cash cow.\" On X, Musk threatened to ban Apple devices at Tesla and his other companies over the deal, which some users interpreted as Musk being jealous of the OpenAI deal."
}
]
}'

The response will return after a few seconds and look something like below:

{
"id": "chatcmpl-5VWGrtNUrh9QpSkc267ZMRa5r47cs",
"object": "chat.completion",
"created": 1718252557,
"model": "gpt-4-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Elon Musk has requested to drop his lawsuit against OpenAI, according to a court filing. He had previously accused OpenAI of deviating from its nonprofit mission and alleged it breached its founding agreement to make AI advances freely available to the public. The request for dismissal comes ahead of a hearing where discovery was supposed to start. OpenAI had contested some of Musk's requests for confidential information. The reasons behind Musk's decision to abandon the suit remain unclear."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 545,
"completion_tokens": 91,
"total_tokens": 636
},
"system_fingerprint": null
}

The choices.message.content field contains the summarised text that we will use as the voice over for the AI avatar.

Generating the AI avatar video with Shotstack and D-ID

The next step is to use the summarised voice over and generate the AI news reader avatar. We will use the Shotstack Create API to generate the avatar video using D-ID.

You will need to make sure you have a D-ID account and API key. You also need to set up the D-ID integration in the Shotstack dashboard following the D-ID guide.

Once the integration is set up, you can use the following cURL command to generate the avatar video. Replace SHOTSTACK_API_KEY with your Shotstack sandbox API key and the value of text with the summarised text from the OpenAI text generation response.

curl -L 'https://api.shotstack.io/create/stage/assets' \
-H 'Content-Type: application/json' \
-H 'x-api-key: SHOTSTACK_API_KEY' \
-d '{
"provider": "d-id",
"options": {
"type": "text-to-avatar",
"text": "Elon Musk has requested to drop his lawsuit against OpenAI, according to a court filing. He had previously accused OpenAI of deviating from its nonprofit mission and alleged it breached its founding agreement to make AI advances freely available to the public. The request for dismissal comes ahead of a hearing where discovery was supposed to start. OpenAI had contested some of Musk'
\''s requests for confidential information. The reasons behind Musk'\''s decision to abandon the suit remain unclear.",
"avatar": "matt",
"background": "#ffffff"
}
}'

You should receive a response that includes an asset id for the generated video. You can use this check the status of the avatar generation using the following cURL command, replacing ASSET_ID with the id from the POST response:

curl -L 'https://api.shotstack.io/create/stage/assets/ASSET_ID' \
-H 'x-api-key: SHOTSTACK_API_KEY'

The response should look like this, once the status equals done:

{
"data": {
"type": "asset",
"id": "01j07-xz50j-btk66-60gj3-4nqctp",
"attributes": {
"owner": "swpwxq9d22",
"provider": "d-id",
"type": "text-to-avatar",
"url": "https://shotstack-create-api-stage-assets.s3.amazonaws.com/swpwxq9d22/01j07-xz50j-btk66-60gj3-4nqctp.mp4",
"status": "done",
"created": "2024-06-13T04:33:49.094Z",
"updated": "2024-06-13T04:36:04.316Z"
}
}
}

If the status is still processing, wait a few seconds and retry the above cURL request until the status is done. The url field contains the link to the generated avatar video.

Next we'll combine the avatar video and title with a news video template to create a complete news video.

Preparing the template in Shotstack Studio

The Shotstack Studio is a web-based video editor, specially designed for bulk video editing, that allows you to create and edit videos using a drag and drop interface. You can create templates from scratch or use one of the many pre-built templates. For this guide, we will use a pre-made news template that includes an avatar, image, lower third, headline and category.

You can find the video templates on this web site or in the template gallery of your Shotstack account. We are going to use this AI avatar news video template for this guide. Click on the Customise Template button to open the template in the Shotstack Studio.

You should see the template in the video editor with an avatar, image, headline and category in the preview window and arranged along the timeline.

Studio editor with AI avatar news video template

Combining the avatar video with the news template

The Shotstack Edit API allows you to replace placeholders in a template with different assets and values. We call these merge fields.

In the news template we have the following merge fields which will be set using the following values:

  • {{ AVATAR }} - The AI avatar video url generated by the Create API
  • {{ HEADLINE }} - The news article title returned by the World News API
  • {{ IMAGE }} - The news article image URL returned by the World News API
  • {{ CATEGORY }} - The news article category which we will hard code to "Technology"

You can send a request to the Edit API templates/render endpoint with different values for each merge field to create a unique video from multiple news articles.

You can use the Studio to export the cURL request from the news template. Back in the Studio, make sure the news template is still open and click on the Use Template button.

In the modal, select API from the list of options. A code panel will open and you can select cURL from the language/library dropdown. Select Template ID from the data format dropdown.

Studio editor merge fields code export

You can copy the cURL command and paste it in to your terminal. Replace the merge fields with all of the value we have generated or retrieved in the previous steps. You will also need to replace TEMPLATE_ID with the template id copied from the code snippet panel.

curl --request POST 'https://api.shotstack.io/stage/templates/render' \
--header 'content-type: application/json' \
--header 'x-api-key: SHOTSTACK_API_KEY' \
--data-binary @- << EOF
{
"id": "TEMPLATE_ID",
"merge": [
{
"find": "AVATAR",
"replace": "https://shotstack-create-api-stage-assets.s3.amazonaws.com/swpwxq9d22/01j07-xz50j-btk66-60gj3-4nqctp.mp4"
},
{
"find": "CATEGORY",
"replace": "TECHNOLOGY"
},
{
"find": "HEADLINE",
"replace": "Breaking: Elon Musk drops claims that OpenAI abandoned mission"
},
{
"find": "IMAGE",
"replace": "https://cdn.arstechnica.net/wp-content/uploads/2024/06/GettyImages-2148557371-760x380.jpg"
}
]
}
EOF

You should receive a response with the render ID that looks similar to this:

{
"success": true,
"message": "Created",
"response": {
"message": "Render Successfully Queued",
"id": "ef054d7a-7ad3-4e41-8b74-50be5c406ece"
}
}

Replace RENDER_ID in the cURL command below with the id from above to check the status of the video render:

curl -L 'https://api.shotstack.io/stage/render/RENDER_ID?data=false&merged=true' \
-H 'content-type: application/json' \
-H 'x-api-key: SHOTSTACK_API_KEY' \

The response should look similar to below, and once the status is set to done you can view or download the video returned for the url value:

{
"success": true,
"message": "OK",
"response": {
"id": "ef054d7c-7ad3-4e41-8a74-50be5c505ece",
"owner": "swpwxq9d22",
"plan": "basic",
"status": "done",
"error": "",
"duration": 39,
"billable": 39,
"renderTime": 19992,
"url": "https://shotstack-api-stage-output.s3-ap-southeast-2.amazonaws.com/swpwxq9d22/ef054d7c-7ad3-4e41-8a74-50be5c505ece.mp4",
"poster": null,
"thumbnail": null,
"created": "2024-06-13T05:22:01.243Z",
"updated": "2024-06-13T05:22:23.313Z"
}
}

Our final automated AI avatar news video looks like this:

Conclusion

This guide should have given you an understanding of how to automate the creation of news videos using AI avatars, news API's and video editing API's. While we manually ran each command using cURL commands, it would be straightforward to fully automate each step to a script or application. The steps in this guide could form the basis for your own AI news video automation workflow or application.

Get started with Shotstack's video editing API in two steps:

  1. Sign up for free to get your API key.
  2. Send an API request to create your video:
    curl --request POST 'https://api.shotstack.io/v1/render' \
    --header 'x-api-key: YOUR_API_KEY' \
    --data-raw '{
    "timeline": {
    "tracks": [
    {
    "clips": [
    {
    "asset": {
    "type": "video",
    "src": "https://shotstack-assets.s3.amazonaws.com/footage/beach-overhead.mp4"
    },
    "start": 0,
    "length": "auto"
    }
    ]
    }
    ]
    },
    "output": {
    "format": "mp4",
    "size": {
    "width": 1280,
    "height": 720
    }
    }
    }'
Jeff Shillitto

BY JEFF SHILLITTO
13th June 2024

Studio Real Estate
Experience Shotstack for yourself.
SIGN UP FOR FREE

You might also like

Convert articles to videos with ChatGPT

Convert articles to videos with ChatGPT

Maab Saleem
AI tools for YouTube automation

AI tools for YouTube automation

Benjamin Semah