How to Auto-Generate Subtitles using PHP?

To auto-generate subtitles with PHP, you can use speech-to-text AI capable of transcribing media files. A video editing API like Creatomate can help you with that. Using its PHP library, you can generate animated, word-by-word captions, directly from your Laravel or any other PHP-based projects:

Input Code
// Don't forget to install the required library using Composer:
// composer require creatomate/creatomate
$client = new Creatomate\Client('Your API Key');

$output = $client->render([
  'source' => new Creatomate\Source([
    'output_format' => 'mp4',
    'elements' => [

      new Creatomate\Elements\Video([
        'id' => '17ca2169-786f-477f-aaea-4a2598bf24eb',
        'source' => ''

      new Creatomate\Elements\Text([
        'transcript_source' => '17ca2169-786f-477f-aaea-4a2598bf24eb',
        'transcript_effect' => 'highlight',
        'transcript_maximum_length' => 14,
        'y' => '82%',
        'width' => '81%',
        'height' => '35%',
        'x_alignment' => '50%',
        'y_alignment' => '50%',
        'fill_color' => '#ffffff',
        'stroke_color' => '#000000',
        'stroke_width' => '1.6 vmin',
        'font_family' => 'Montserrat',
        'font_weight' => '700',
        'font_size' => '9.29 vmin',
        'background_color' => 'rgba(216,216,216,0)',
        'background_x_padding' => '31%',
        'background_y_padding' => '17%',
        'background_border_radius' => '31%'


Output Video

How it works: First, install the Creatomate package from Packagist using Composer. This library provides the interface between your application and the video API, making it possible to run video editing tasks from your PHP code.

In order to create the videos, we call the "render" function and pass instructions to the API about how to compose the video. As shown in this example, we provide a video and a text element. The video element contains the clip that we want to generate subtitles for, whereas the text element is a container for the subtitle captions.

Auto-transcription is enabled with the "transcript_source" attribute of the text element. Specifying the ID of the video element tells the API which video element to use as a source for the auto-generated subtitles.

The remaining attributes are used to style, position, and animate the captions. You can adjust a variety of attributes to customize the subtitles in a particular way. For setting up a custom video template, try out the online video editor below to explore the different subtitle options.

Auto-transcription is just one of Creatomate's features. With its developer-driven approach, you can automate any video editing task to create dynamic videos, right from your PHP apps. To get started, follow this quick tutorial or check out the API documentation.

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