PHP code example of mokhosh / laravel-caption

1. Go to this page and download the library: Download mokhosh/laravel-caption library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mokhosh / laravel-caption example snippets


use Mokhosh\LaravelCaption\Caption;use Mokhosh\LaravelCaption\Generators\SrtGenerator;use Mokhosh\LaravelCaption\Line;

// $response = OpenAI::audio()->transcribe();

$caption = new Caption;

foreach ($response->segments as $segment) {
    $caption->add(new Line(
        floatval($segment->start),
        floatval($segment->end) - floatval($segment->start),
        trim($segment->text),
    ));
}

SrtGenerator::load($caption)->export('output.srt');

use Mokhosh\LaravelCaption\Facades\LaravelCaption;

// convert to srt and return output path
$output = LaravelCaption::openai2srt('input.json', 'output.srt');

use Mokhosh\LaravelCaption\Facades\LaravelCaption;

// convert to srt and return output path
$output = LaravelCaption::xml2srt('input.xml', 'output.srt');

use Mokhosh\LaravelCaption\Facades\LaravelCaption;

// chunk every 10 lines into chunks/ folder and return an array of chunks' paths
$chunks = LaravelCaption::xml2srt('input.xml', 'chunks/', every: 10);

use Mokhosh\LaravelCaption\Generators\SrtGenerator;use Mokhosh\LaravelCaption\Parsers\XmlCaptionParser;

$caption = XmlCaptionParser::import('input.xml')->parse();
$output = SrtGenerator::load($caption)->export('output.srt');

use Mokhosh\LaravelCaption\Generators\SrtGenerator;use Mokhosh\LaravelCaption\Parsers\XmlCaptionParser;

$caption = XmlCaptionParser::import('input.xml')->parse();
// chunk every 4 lines into chunks folder and prefix chunk files with the word "part"
$chunks = SrtGenerator::load($caption)->chunk(4, 'chunks/', 'part');