0

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>
mountain traveller
  • 7,591
  • 33
  • 38
  • Realized the code was working when using a uInt8Array instead of Int16Array (though the Amazon API states pcm is in 16 bit signed format). I had played around with both before but realized my issue was that I didn't have a media player able to play the file. – tchallajr Mar 07 '19 at 15:29
  • This might be helpful - https://stackoverflow.com/questions/45826745/using-pcm-format-of-aws-polly – asr9 Mar 26 '19 at 21:24

1 Answers1

0

If you are sure the url object is correct (can you download it from a separate browser tab?), I would use JQuery to dynamically change your DOM, as per this answer How to change the href for a hyperlink using jQuery

Sébastien Stormacq
  • 14,301
  • 5
  • 41
  • 64