How to Add an AI Voice Over to a Video using PHP?

This PHP example shows how to generate AI voiceovers in your web application. It uses ElevenLabs' text-to-speech API, along with Creatomate. Just specify a template, provide the voiceover text, and generate the video using a single API request:

Input Code
// composer require creatomate/creatomate
$client = new Creatomate\Client('Your API Key');

$output = $client->render([
 // Design your own template, and provide its ID here.
 'template_id' => '2e8bccbf-e40a-41d5-a815-f58518ed9835',

 // Specify the text to be read aloud.
 'modifications' => [
  'Voiceover-1' => 'The 3 Best Tips for Healthy Eating',
  'Voiceover-2' => 'Prioritize Whole Foods: Opt for fruits, vegetables, whole grains, lean proteins and healthy fats. They\'re packed with nutrients and fiber for overall health.',
  'Voiceover-3' => 'Stay Hydrated: Drink plenty of water to support digestion, regulate temperature, and maintain health. Limit sugary drinks and make water your go-to beverage.',
  'Voiceover-4' => 'Plan Meals: Prep your meals and snacks ahead of time to avoid impulsive, unhealthy food choices. Keep nutritious foods on hand to stay on track with your health goals.'
 ]
]);

var_dump($output);
Output Video

How it works: The quickest way to get started is using this step-by-step tutorial. PHP users can use Creatomate's Packagist package to invoke the API directly from their PHP or Laravel applications. With this package, creating a voice-over video is as simple as calling the function "render".

The function accepts two parameters: the template ID and the voiceover sentences. Templates can be crafted using the online video editor or provided in JSON format. This appraoach offers a lot of flexibility, whether you're making social media videos or professional voiceovers for online courses.

You have the freedom to decide the extent of automation in your video production process, from simple voiceovers to fully AI-generated videos. Creatomate's API integrates seamlessly with major AI tools, allowing you to use ChatGPT for scriptwriting and DALL·E for AI-generated images. Additionally, you can choose from dozens of subtitle styles, featuring animated captions that sync perfectly with the spoken text.

Creating voiceover videos is just one of Creatomate's many capabilities. With its developer-focused design, you can automate any video editing task to produce dynamic videos directly from your PHP applications.

Sign up for a free account and give it a try.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your PHP application to create any kind of video – completely through code.

Related PHP Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free