【问题标题】:Save AWS Polly mp3 file to S3将 AWS Polly mp3 文件保存到 S3
【发布时间】:2023-03-10 18:06:01
【问题描述】:

我正在尝试向 AWS Polly 发送一些文本以转换为语音,然后将该 mp3 文件保存到 S3。这部分现在似乎起作用了。

// 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'];

我也在尝试完成其他几件事:

  1. 使 mp3 文件可公开访问。目前我必须去 AWS 控制台 点击“公开”按钮。 'ACL' => 'public-read' 似乎对我不起作用

  2. 我需要返回 mp3 文件的完整 URL。出于某种原因 $result_polly['ObjectURL'];没有任何价值。

我错过了什么?

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-polly


    【解决方案1】:

    StartSpeechSynthesisTask call 中没有 ACL 字段:

    $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
    ]);
    

    因此,您需要再次调用 Amazon S3 来更改对象的 ACL,或者使用 Amazon S3 Bucket Policy 来创建存储桶(或存储桶内的路径)公开。

    输出位置在OutputUri 字段中给出(不是 OutputUrl -- URI vs URL)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      相关资源
      最近更新 更多