我正在尝试从中实现代码this site 在代码中,以下行导致错误,并且未加载我的页面--
use \\Aws\\Polly\\PollyClient;
如果我注释掉代码,那么页面加载很好,除了我尝试使用的脚本无法工作之外,我没有收到任何错误。
代码似乎相当标准的php,所以我想知道这是否是因为它是wordpress,我需要做一些其他的事情来使用-“使用”?
完整代码---
//include_once (\'/polly/aws-autoloader.php\');
require_once (\'/polly/aws-autoloader.php\');
use \\Aws\\Polly\\PollyClient;
if(isset($_REQUEST[\'voice\']) && $_REQUEST[\'voice\'] != \'\') {
$voice_id = $_REQUEST[\'voice\'];
} else {
$voice_id="Joanna";
}
if(isset($_REQUEST[\'text\']) && $_REQUEST[\'text\'] != \'\') {
$text = trim(strip_tags($_REQUEST[\'text\']));
}
if(isset($_REQUEST[\'rate\']) && $_REQUEST[\'rate\']!=\'\') {
$rate=$_REQUEST[\'rate\'];
} else {
$rate="medium";
}
$is_download = false;
if(isset($_REQUEST[\'download\']) && $_REQUEST[\'download\']==1) {
$is_download=true;
}
$config = [
\'version\' => \'latest\',
\'region\' => \'us-east-1\',
\'credentials\' => [
\'key\' => \'MY KEYS\',
\'secret\' => \'MY KEYS\',
]
];
$client = new PollyClient($config);
$args = [
\'OutputFormat\' => \'mp3\',
\'Text\' => "<speak><prosody rate=\'$rate\'>".str_replace("&","&",urldecode ($text))."</prosody></speak>",
\'TextType\' => \'ssml\',
\'VoiceId\' => $voice_id,
];
$result = $client->synthesizeSpeech($args);
$resultData = $result->get(\'AudioStream\')->getContents();
$size = strlen($resultData); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
if(!$is_download) {
header(\'Content-Transfer-Encoding:chunked\');
header("Content-Type: audio/mpeg");
header("Accept-Ranges: 0-$length");
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: $length");
echo $resultData;
} else {
header(\'Content-length: \' . strlen($resultData));
header(\'Content-Disposition: attachment; filename="polly-text-to-speech.mp3"\');
header(\'X-Pad: avoid browser bug\');
header(\'Cache-Control: no-cache\');
echo $resultData;
}