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:
- Polly docs: http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-polly-2016-06-10.html
- Polly pricing: https://aws.amazon.com/polly/pricing/
- Getting started with AWS PHP SDK: http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/
No hay comentarios:
Publicar un comentario