我正在尝试使用 Amazon 的 PHP SDK 将 Amazon Polly Web 服务集成到我的一个项目中。但是当我使用 PollyClient SDK 时,客户端中只实现了一种方法createSynthesizeSpeechPreSignedUrl()
,它返回一个 url,而不是音频剪辑。当我尝试将 url 粘贴到浏览器窗口中时,出现以下错误:"message": "The security token included in the request is invalid."
请看我的代码片段:
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: text/plain; charset=utf-8');
require_once 'app/aws/aws-autoloader.php';
use Aws\Polly\PollyClient;
class TestPolly extends Base {
public function newPolly () {
$connection = [
'region' => 'us-west-2',
'version' => 'latest',
'debug' => true,
'scheme' => 'http',
'credentials' => [
'key' => 'XXXXX',
'secret' => 'XXXXXX',
],
];
$client = new PollyClient($connection);
$polly_args = [
'OutputFormat' => 'mp3',
'Text' => 'My Input text',
'TextType' => 'text',
'VoiceId' => 'Brain',
];
$result = $client->synthesizeSpeech($polly_args);
echo '<pre>';
print_r($result);
exit;
}
}
我得到的 PHP 错误是:
Fatal error Uncaught exception 'Aws\Polly\Exception\PollyException' with message 'Error executing "SynthesizeSpeech on http://polly.us-west-2.amazonaws.com/v1/speech
AWS HTTP error: cURL error 7: Failed to connect to polly.us-west-2.amazonaws.com port 80: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)'
exception 'GuzzleHttp\Exception\ConnectException' with message 'cURL error 7: Failed to connect to polly.us-west-2.amazonaws.com port 80: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in D:\xampp\htdocs\sim_aws\aws\GuzzleHttp\Handler\CurlFactory.php:186
Stack trace:
有趣的是,我能够使用 Node.js SDK 生成音频剪辑,所以我很确定访问密钥和密钥工作正常。
如果有人能指出 PHP SDK 如何与示例代码或有用的链接一起使用,那就太好了。