Trying to transcribe an audio file stored in a S3 bucket which I have access, with AWS SDK PHP API, as follows, gives me a throttling exception: rate exceeded.
I have read the documentation a dozen of times and can't find a simple working example that shows how to successfully transcribe a file with AWS transcribe and their PHP API.
date_default_timezone_set('America/New_York');
try
{
require '/var/www/html/aws/sdk/aws-autoloader.php';
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
use Aws\TranscribeService\TranscribeServiceClient;
$client = new Aws\TranscribeService\TranscribeServiceClient([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => 'xxxx',
'secret' => 'yyyy',
'curl.options' => array(CURLOPT_VERBOSE => true)
]
]);
$job_name = "tjob".date("mdyhisa");
$job_uri = "https://s3.amazonaws.com/....mp3";
$result = $client->startTranscriptionJob([
'LanguageCode' => 'en-US',
'Media' => [
'MediaFileUri' => "$job_uri",
],
'MediaFormat' => 'mp3',
'TranscriptionJobName' => "$job_name",
]);
/* removing this loop and the sleep() below would retrieve some structured response,
but of course the operation status is IN_PROGRESS */
while(true)
{
/* added to discover if holding a few seconds would work: it doesn't
and gives back a 504 Gateway Timeout */
sleep(rand(3,5));
/* -- */
$result = $client->getTranscriptionJob(['TranscriptionJobName' => "$job_name"]);
if ( ($result['TranscriptionJob']['TranscriptionJobStatus']=='COMPLETED') || ($result['TranscriptionJob']['TranscriptionJobStatus']=='FAILED'))
{
break;
}
}
var_dump($result);
So question is: how to get the transcription output?
By the way, I don't need this asynchronously...it is fine for my little project to wait for it to process and return.