1

Ich versuche meine Amazon Polly-Sprachdateien auf s3 hochzuladen. Sie laden erfolgreich hoch, also keine Fehler, mit denen ich arbeiten kann, aber sie spielen nicht.s3 lädt die Audiodatei hoch, spielt sie aber nicht ab. Wie lade ich einen Audiostream nach s3 hoch?

Ich habe eine Reihe von Objekten, die Texte enthalten, die Strings sind. Ich loop sie und erstellen Sie eine MP3-Datei dann auf s3 hochladen.


Datenstruktur:

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

     ) 

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

     ) 

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

     ) 

) 

.
Polly und S3 Funktion:

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"; 
    } 

} 

Polly Antwort:

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 
             (
             ) 

           ) 

         ) 

       ) 

     ) 

) 

Antwort

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

So scheint es, wie ich das ganze Objekt auf S3 zu laden versucht. Mit der obigen Zeile kann ich den Audiostream ordnungsgemäß hochladen.

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"; 
    } 

} 
Verwandte Themen