PHP code example of masterfermin02 / php-audio-text-summary
1. Go to this page and download the library: Download masterfermin02/php-audio-text-summary 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/ */
masterfermin02 / php-audio-text-summary example snippets
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
use DaimonDove\Transcription\Transcriber;
$client = OpenAI::client('YOUR_API_KEY');
$googleCredentials = ['credentials' => 'YOUR_GOOGLE_API_CREDENTAILS'];
$speechToText = Transcriber::create($client, $googleCredentials);
# The name of the audio file to transcribe
$gcsURI = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw';
# set string as audio content
$audio = (new RecognitionAudio())
->setUri($gcsURI);
# The audio file's encoding, sample rate and language
$config = new RecognitionConfig([
'encoding' => AudioEncoding::LINEAR16,
'sample_rate_hertz' => 16000,
'language_code' => 'en-US'
]);
echo $speechToText->recognize($config, $audio)
->summary();
// Get others alternatives for tests
$response = $speechToText->getRecognizeText();
# Print most likely transcription
foreach ($response->getResults() as $result) {
$alternatives = $result->getAlternatives();
$mostLikely = $alternatives[0];
$transcript = $mostLikely->getTranscript();
printf('Summary: %s' . PHP_EOL, $speechToText->summaryText($transcript));
}
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\StreamingRecognitionConfig;
use DaimonDove\Transcription\Transcriber;
$recognitionConfig = new RecognitionConfig();
$recognitionConfig->setEncoding(AudioEncoding::FLAC);
$recognitionConfig->setSampleRateHertz(44100);
$recognitionConfig->setLanguageCode('en-US');
$config = new StreamingRecognitionConfig();
$config->setConfig($recognitionConfig);
$audioResource = fopen('path/to/audio.flac', 'r');
$client = OpenAI::client('YOUR_API_KEY');
$googleCredentials = ['credentials' => 'YOUR_GOOGLE_API_CREDENTAILS'];
$speechToText = Transcriber::create($client, $googleCredentials);
echo $speechToText->recognizeAudioStream($config, $audioResource)->summary();
$responses $speechToText->getRecognizeAudioStreamText();
foreach ($responses as $element) {
// doSomethingWith($element);
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.