pplu / aws-sdk-perl

A community AWS SDK for Perl Programmers
Other
171 stars 94 forks source link

Paws::Polly->SynthesizeSpeech tries to interpret binary data (MP3) as JSON #143

Closed iafan closed 7 years ago

iafan commented 7 years ago

Here's a simple script I use to try Paws::Polly:

use strict;

use Paws;

$ENV{AWS_ACCESS_KEY} = 'xxxxxxxxxxxxxxxxx';
$ENV{AWS_SECRET_KEY} = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

my $polly = Paws->service('Polly', region => 'us-west-2');

my $res = $polly->SynthesizeSpeech(
    VoiceId => 'Joanna',
    Text => 'This is a test',
    OutputFormat => 'mp3',
);

open(MP3, ">out.mp3");
binmode(MP3);
print MP3 $res;
close(MP3);

When I try to run it (I'm on Windows x64, if that matters), I get the following error:

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0
(before "ID3\x{4}\x{0}\x{0}\x{0}...") at C:/Perl/perl/site/lib/Paws/Net/RestJsonResponse.pm
line 34, <DATA> line 1.

The ID3..... signature suggests that I'm getting the binary MP3 content (which is what I want), but I'm not sure why Paws tries to interpret the result as JSON (and, obviously, fails).

pplu commented 7 years ago

Hi,

It looks like RestJsonCaller is not handling the fact that AudioStream is transmitted in the body of the request. I'll take a look at how we can fix this, since RestJsonCaller was not prepared (yet) for this type of behaviour (Polly is a quite new service, so it hasn't been fully tried out yet in Paws).

I'll try to get this working as soon as I can

pplu commented 7 years ago

Hi,

I've got it partially working (the Audio content is served and returned correctly, but the information that comes from the headers (ContentType and RequestChars) aren't returned correctly (yet).

The changes needed are here: https://github.com/pplu/aws-sdk-perl/commit/ff1db0de4374f1ae94489127d53a1fcd2b1531d1 (more changes to come regarding this issue in https://github.com/pplu/aws-sdk-perl/compare/feat/restjson_streamingresponses)

pplu commented 7 years ago

This problem was solved in 0.32 (pushed to CPAN some months ago)