I have a page that has jquery and the amazon SDK. There is text in an area box that the user can change. I successfully make the request to Amazon. I get back the PCM AudioStream (Int16Array). How do I then convert this stream to a downloadable PCM file? When the file downloads, the file is useless and can't be played. The file does have a size greater than 0, so that makes me believe there is data there.
<script>
AWS.config.region = 'us-east-1';
AWS.config.accessKeyId = 'CANDY';
AWS.config.secretAccessKey = 'CANES';
var polly = new AWS.Polly({apiVersion: '2016-06-10'});
var params = {
OutputFormat: 'pcm',
Text: 'Text from the textbox',
VoiceId: 'Joey',
SampleRate: '16000',
TextType: 'text'
};
polly.synthesizeSpeech(params, function(err, data) {
if (err){
console.log(err, err.stack); // an error occurred
} else {
var stream = new Int16Array(audioStream);
var arrayBuffer = stream.buffer;
var blob = new Blob([arrayBuffer], {type: 'audio/pcm'});
var url = URL.createObjectURL(blob);
.....set href for link to url.......
}
});
</script>