AWS使用PHP API转录:限制例外:超出费率

问题描述 投票:0回答:1

尝试使用AWS SDK PHP API转录存储在我有权访问的S3存储桶中的音频文件,如下所示,给出了一个限制异常:超出速率。

我已经阅读了十几次文档,但找不到一个简单的工作示例,该示例演示了如何使用AWS转录及其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);

所以问题是:如何获得转录输出?

顺便说一句,我不需要异步...我的小项目等待它处理和返回是好的。

php amazon-web-services aws-transcribe
1个回答
0
投票

你的代码可能工作正常,但你的while(true)循环调用API太多次,因此throttling exception: rate exceeded错误。

我建议你在每次打电话给getTranscriptionJob之间延迟5秒。我发现一份工作可能需要大约60秒才能完成,所以你不需要连续调用它。

© www.soinside.com 2019 - 2024. All rights reserved.