1

Amazon Pollyの音声ファイルをs3にアップロードしようとしています。彼らは正常にアップロードされるので、私は一緒に作業することはできますが、再生しないエラーはありません。s3はオーディオファイルをアップロードしますが、再生しません。どのようにs3にオーディオストリームをアップロードするには?

私は文字列である歌詞を含むオブジェクトの配列を持っています。私はそれらをループし、mp3ファイルを作成してからs3にアップロードします。


データ構造:

Array 
(
    [0] => stdClass Object 
     (
      [lyrics] => sample lyrics 

     ) 

    [1] => stdClass Object 
     (
      [lyrics] => sample lyrics 

     ) 

    [2] => stdClass Object 
     (
      [lyrics] => sample lyrics 

     ) 

) 


ポリーとS3機能:

foreach($final as $key=>$f){ 

    $pollySpeech = $polly->synthesizeSpeech([ 
     'OutputFormat' => 'mp3', 
     'Text' => $f->lyrics, 
     'TextType' => 'text', 
     'VoiceId' => 'Salli', 
    ]); 

    print_r($pollySpeech); 

    try { 
     $s3->putObject([ 
       'Bucket' => 'testbucket' 
       'Key' => $key.'.mp3', 
       'Body' => $pollySpeech, 
       'ContentType' => 'audio/mpeg', 
      'ACL' => 'public-read', 
     ]); 
    } catch (Aws\S3\Exception\S3Exception $e) { 
     echo "There was an error uploading the file.\n"; 
    } 

} 

ポリー応答:私はS3にオブジェクト全体をアップロードしようとしたよう

Aws\Result Object 
(
    [data:Aws\Result:private] => Array 
     (
      [AudioStream] => GuzzleHttp\Psr7\Stream Object 
       (
        [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #264 
        [size:GuzzleHttp\Psr7\Stream:private] => 
        [seekable:GuzzleHttp\Psr7\Stream:private] => 1 
        [readable:GuzzleHttp\Psr7\Stream:private] => 1 
        [writable:GuzzleHttp\Psr7\Stream:private] => 1 
        [uri:GuzzleHttp\Psr7\Stream:private] => php://temp 
        [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array 
         (
         ) 

       ) 

      [ContentType] => audio/mpeg 
      [RequestCharacters] => 90 
      [@metadata] => Array 
       (
        [statusCode] => 200 
        [effectiveUri] => https://polly.eu-west-1.amazonaws.com/v1/speech 
        [headers] => Array 
         (
          [x-amzn-requestid] => fc1a7ebf-4f8c-11e7-a1a3-555e1409e93f 
          [x-amzn-requestcharacters] => 90 
          [content-type] => audio/mpeg 
          [transfer-encoding] => chunked 
          [date] => Mon, 12 Jun 2017 16:34:20 GMT 
         ) 

        [transferStats] => Array 
         (
          [http] => Array 
           (
            [0] => Array 
             (
             ) 

           ) 

         ) 

       ) 

     ) 

) 

答えて

0
$pollySpeech->get('AudioStream')->getContents(); 

だから、それはそう。上記の行は、私がオーディオストリームを適切にアップロードできるようにします。

foreach($final as $key=>$f){ 

    $pollySpeech = $polly->synthesizeSpeech([ 
     'OutputFormat' => 'mp3', 
     'Text' => $f->lyrics, 
     'TextType' => 'text', 
     'VoiceId' => 'Salli', 
    ]); 

    print_r($pollySpeech); 

    try { 
     $s3->putObject([ 
       'Bucket' => 'testbucket' 
       'Key' => $key.'.mp3', 
       'Body' => $pollySpeech->get('AudioStream')->getContents(), 
       'ContentType' => 'audio/mpeg', 
      'ACL' => 'public-read', 
     ]); 
    } catch (Aws\S3\Exception\S3Exception $e) { 
     echo "There was an error uploading the file.\n"; 
    } 

} 
関連する問題