martes, 23 de enero de 2018

PHP AMAZON Polly

Here is some sample code to download the TTS as an .mp3 file in the browser, the crucial part is $result->get('AudioStream')->getContents() this is what gets the actual .mp3 data.
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;
A for links, here are a few:

No hay comentarios:

Publicar un comentario