I want to generate text file from the video. I have used Google Speech to Text service in Laravel 5.6.
Service/Package used
Code
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
use Google\Cloud\Speech\V1\SpeechClient;
$jsonFileUrl = Storage::disk('local')->path(''); //Googel service account json file path
putenv("GOOGLE_APPLICATION_CREDENTIALS=$jsonFileUrl");
$videoFile = Storage::disk('review')->path('UHD_4K_65_TV.mp4');
$encoding = AudioEncoding::LINEAR16;
$sampleRateHertz = 32000;
$languageCode = 'en-US';
$content = file_get_contents($videoFile);
$audio = (new RecognitionAudio())
->setContent($content);
$config = (new RecognitionConfig())
->setEncoding($encoding)
->setSampleRateHertz($sampleRateHertz)
->setLanguageCode($languageCode)
->setModel('video');
$client = new SpeechClient();
$response = $client->longRunningRecognize($config, $audio);
$response->pollUntilComplete();
if ( $response->operationSucceeded () ) {
foreach ($response->getResult ()->getResults() as $result) {
$saida = [ 'transcript' => [], 'word' => [] ];
$alternatives = $result->getAlternatives ();
$mostLikely = $alternatives[ 0 ];
$transcript = $mostLikely->getTranscript ();
$confidence = $mostLikely->getConfidence ();
$saida[ 'transcripts' ][] = [
'transcript' => $transcript,
'confidence' => $confidence
];
foreach ( $mostLikely->getWords () as $wordInfo ) {
$saida[ 'words' ][] = [
'word' => $wordInfo->getWord (),
'start' => GPBUtil::formatDuration ( $wordInfo->getStartTime () ),
'end' => GPBUtil::formatDuration ( $wordInfo->getEndTime () )
];
}
dd($saida);
}
} else {
dd($response->getError ());
}
$client->close();
Result
["transcript"=>[],"word"=>[],"transcripts"=>[0=>["transcript"=>"","confidence"=>0.0]]]
Sample video: https://vimeo.com/425422475/ff471a7edb
I have to generate text from above video speech.
I have successfully generate the text file of this video from https://cloud.google.com/speech-to-text
Please suggest how can I convert video using API.