예제 #1
0
 public static function create($videoId, $text, $api = Captionify::API_JTALK)
 {
     //this might take up to 2 mins to finish, so let make that provision
     set_time_limit(120);
     //we want to always start afresh when captionifying text
     //so delete all existing caption before we start
     $captions = VideoCaption::collection(['video_id' => $videoId]);
     foreach ($captions as $caption) {
         $caption->delete();
     }
     $text = str_replace('. ', "\n", $text);
     $sentences = explode("\n", $text);
     $result = array();
     $lastEnd = 0;
     foreach ($sentences as $sentence) {
         switch ($api) {
             case self::API_TTSAPI:
                 $caption = self::_jTalkCaptionify($sentence, $lastEnd, 0);
                 break;
             case self::API_JTALK:
             default:
                 $caption = self::_ttsApiCaptionify($sentence, $lastEnd, 0);
                 break;
         }
         if ($caption) {
             $lastEnd += $caption['duration'];
             $result[] = $caption;
         }
     }
     foreach ($result as $captionData) {
         $caption = new VideoCaption();
         $caption->videoId = $videoId;
         $caption->startSecond = $captionData['start'];
         $caption->endSecond = $captionData['end'];
         $caption->text = $captionData['text'];
         $caption->saveChanges();
     }
 }