I am trying to implement code from this site and in the code the following line is causing an error and my page is not loaded --
use \Aws\Polly\PollyClient;
If I comment the code out then the page loads fine and I get no errors besides that the script I tried to use wont work.
Code seems pretty standard php so im wondering if it's cause it's wordpress and I would need to do something else to be to use - "use" ?
FULL CODE ---
//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;
}
/polly/aws-autoloader.phpseems off (see this thread)Parse error: syntax error, unexpected 'use' (T_USE) in /var/......