【发布时间】:2016-12-10 00:15:40
【问题描述】:
这是我的脚本:
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.7.13.min.js"></script>
<script>
AWS.config.region = 'eu-west-1';
AWS.config.accessKeyId = 'FOO';
AWS.config.secretAccessKey = 'BAR';
var polly = new AWS.Polly({apiVersion: '2016-06-10'});
var params = {
OutputFormat: 'mp3', /* required */
Text: 'Hello world', /* required */
VoiceId: 'Joanna', /* required */
SampleRate: '22050',
TextType: 'text'
};
polly.synthesizeSpeech(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
</script>
请求成功,我得到这样的响应:
我如何使用这种响应?我知道响应是反序列化的音频,但我如何实际播放它,比如在 HTML5 音频元素中?
此外,SO 上的这个答案解释了为什么这种类型的数组适用于音频数据:https://stackoverflow.com/a/26320913/1325575
【问题讨论】:
标签: javascript html amazon-web-services audio amazon-polly