Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save coder618/968cbde3e0bfd954dcab8c69eb5ed24c to your computer and use it in GitHub Desktop.
Save coder618/968cbde3e0bfd954dcab8c69eb5ed24c to your computer and use it in GitHub Desktop.
Amazon polly API with Dutch Language (PHP)
<?php
// require_once 'app/aws/aws-autoloader.php';
require 'vendor/autoload.php';
$awsAccessKeyId = '-----';
$awsSecretKey = '-----';
$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' => "A. D",
'TextType' => 'text',
'VoiceId' => 'Lotte',
'LanguageCode' => 'nl-NL'
]);
$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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment