Save AWS Polly mp3 file to S3

Asked by At

I am trying to send some text to AWS Polly to convert to speech and then save that mp3 file to S3. That part seems to work now.

// Send text to AWS Polly
$client_polly = new Aws\Polly\PollyClient([
    'region' => 'us-west-2',
    'version' => 'latest',
    'credentials' => [
        'key' => $aws_useKey,
        'secret' => $aws_secret,

$text = 'Test. Test. This is a sample text to be synthesized.';
$voice = 'Matthew';

 $result_polly = $client_polly->startSpeechSynthesisTask([
    'Text' => $text,
    'TextType' => 'text',
    'OutputFormat' => 'mp3',
    'OutputS3BucketName' => $aws_bucket,
    'OutputS3KeyPrefix' => 'files/audio/,
    'VoiceId' => $voice,
    'ACL' => 'public-read'

echo $result_polly['ObjectURL'];

I'm also trying to accomplish couple other things:

  1. Make mp3 file publicly accessible. Currently I have to go to AWS console to click "Make Public" button. It seems that 'ACL' => 'public-read' doesn't work for me

  2. I need to return full URL of the mp3 file. For some reason $result_polly['ObjectURL']; doesn't get any value.

What am I missing?

1 Answers

John Rotenstein On Best Solutions

There is no ACL field in the StartSpeechSynthesisTask call:

$result = $client->startSpeechSynthesisTask([
    'LanguageCode' => 'arb|cmn-CN|cy-GB|da-DK|de-DE|en-AU|en-GB|en-GB-WLS|en-IN|en-US|es-ES|es-MX|es-US|fr-CA|fr-FR|is-IS|it-IT|ja-JP|hi-IN|ko-KR|nb-NO|nl-NL|pl-PL|pt-BR|pt-PT|ro-RO|ru-RU|sv-SE|tr-TR',
    'LexiconNames' => ['<string>', ...],
    'OutputFormat' => 'json|mp3|ogg_vorbis|pcm', // REQUIRED
    'OutputS3BucketName' => '<string>', // REQUIRED
    'OutputS3KeyPrefix' => '<string>',
    'SampleRate' => '<string>',
    'SnsTopicArn' => '<string>',
    'SpeechMarkTypes' => ['<string>', ...],
    'Text' => '<string>', // REQUIRED
    'TextType' => 'ssml|text',
    'VoiceId' => 'Aditi|Amy|Astrid|Bianca|Brian|Carla|Carmen|Celine|Chantal|Conchita|Cristiano|Dora|Emma|Enrique|Ewa|Filiz|Geraint|Giorgio|Gwyneth|Hans|Ines|Ivy|Jacek|Jan|Joanna|Joey|Justin|Karl|Kendra|Kimberly|Lea|Liv|Lotte|Lucia|Mads|Maja|Marlene|Mathieu|Matthew|Maxim|Mia|Miguel|Mizuki|Naja|Nicole|Penelope|Raveena|Ricardo|Ruben|Russell|Salli|Seoyeon|Takumi|Tatyana|Vicki|Vitoria|Zeina|Zhiyu', // REQUIRED

Therefore, you will either need to make another call to Amazon S3 to change the ACL of the object, or use an Amazon S3 Bucket Policy to make the bucket (or a path within the bucket) public.

The output location is given in the OutputUri field (NOT OutputUrl -- URI vs URL).