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";
}
}
波利迴應:
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
(
)
)
)
)
)
)