- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 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 生成音频剪辑,所以我非常确定访问 key 和 secret key 工作正常。
如果有人能指出如何将 PHP SDK 与示例代码或有用的链接一起使用,那就太好了。
最佳答案
下面是一些示例代码,用于在浏览器中将 TTS 下载为 .mp3 文件,关键部分是 $result->get('AudioStream')->getContents()
,这是什么获取实际的 .mp3 数据。
require_once 'app/aws/aws-autoloader.php';
$awsAccessKeyId = 'XXXXXXX';
$awsSecretKey = 'XXXXXXX';
$credentials = new \Aws\Credentials\Credentials($awsAccessKeyId, $awsSecretKey);
$client = new \Aws\Polly\PollyClient([
'version' => '2016-06-10',
'credentials' => $credentials,
'region' => 'us-east-1',
]);
$result = $client->synthesizeSpeech([
'OutputFormat' => 'mp3',
'Text' => "My input text",
'TextType' => 'text',
'VoiceId' => 'Joanna',
]);
$resultData = $result->get('AudioStream')->getContents();
header('Content-Transfer-Encoding: binary');
header('Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3');
header('Content-length: ' . strlen($resultData));
header('Content-Disposition: attachment; filename="pollyTTS.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
echo $resultData;
至于链接,这里有几个:
关于php - 使用 PHP SDK 的 Amazon Polly 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43320716/
我正在尝试为我的 Rest 客户创建一个综合弹性策略,为此我编写了以下内容: private static Policy circuitBreakerPolicy = Policy .Han
我以前从未使用过 Polly,不确定这是否适合 Polly。 我正在调用 POST 正文中包含 1000 个 DTO 列表的端点。现在,端点将对每个 DTO 执行一些验证,如果这些 DTO 中的任何一
我将 Polly 与 .net Core 结合使用。我的 ConfigureServices 是: private static void ConfigureServices() { var
我正在使用 .NET 5 并希望使用 Polly 在重试时更改请求的查询字符串。背景 - 我有一个固定的每分钟请求配额,这是我的 IP 地址所允许的。如果超过限制,我会得到一个特定的 4xx 状态代码
Polly 中是否有办法重试除指定异常之外的所有异常。例如: var p = Policy .Handle(e => !(e.NativeErrorCode == 1)) .Or()
我们正在考虑使用 Polly 作为我们的故障转移库。 我们在 kubernetes 环境中运行我们的应用程序。例如,我们无法保证针对特定服务运行重试尝试的 pod 将存活足够长的时间以使请求成功。如果
我正在尝试使超时策略正常工作。我在集成 api 时有以下需求。 创建一个 http 请求来调用 endpoint1 并传递 transactionID 并捕获结果 如果 http 请求在 20 秒内没
在启动过程中,我基本上添加了一个 HttpClient,如下所示: services.AddHttpClient().AddPolicyHandler(GetRetryPolicy()); publi
在策略定义中,我希望能够在运行时禁用或启用该策略,而不是在调用站点中进行,因为我可能有多个调用站点。 这是我目前的方法? private RetryPolicy GetRetryPolicy() {
我对波利很陌生。我做了一些研究,但仍然无法确定是否/如何仅在请求失败时以优雅的方式使用 Polly 来使用 chached 值。例子: 服务 A 想通过 http 从服务 B 获取数据。我总是想获取最
我正在使用 AWS Polly 服务进行文本转语音。但是如果文本包含一些特殊字符,它会返回错误的开始和结束编号。 例如,如果文本是:“Böylelikle”,它返回:{"time":6,"type":
我试图重试失败的操作 3 次。 我正在使用 Polly 进行重试操作。 我想在重试操作失败的情况下获得异常并重试 2 次,依此类推。 return await Policy .H
我已经阅读了 Polly 库的文档和示例,它真的很棒而且易于使用!! 就我而言,我想将所有异常分为 3 种类型:临时、永久和日志。现在,我想要一段代码,负责通过使用 Polly 库进行等待和重试来处理
我在 PolicyRegistry 中有以下政策可以在全局范围内重复使用: var fallbackPolicy = Policy .Handle().OrInner()
我正在尝试检查 Polly 的简单 RetryForever class Program { public static void Main() {
我已经阅读了 Polly 库的文档和示例,它真的很棒而且易于使用!! 就我而言,我想将所有异常分为 3 种类型:临时、永久和日志。现在,我想要一段代码,负责通过使用 Polly 库进行等待和重试来处理
我在 PolicyRegistry 中有以下政策可以在全局范围内重复使用: var fallbackPolicy = Policy .Handle().OrInner()
我正在使用一个非常不稳定的 API。有时我会收到 500 服务器错误 和 Timeout,有时我也会收到 500 服务器错误,因为我给它提供了它无法处理的输入 SqlDateTime overflow
我正在尝试检查 Polly 的简单 RetryForever class Program { public static void Main() {
我想执行某个操作,如果失败3次则返回null。 Polly 中类似的东西将是完美的: var results = await Policy> .Handle() .RetryAsync
我是一名优秀的程序员,十分优秀!