I am using https://pub.dev/packages/sigv4 dart package to make a request to AWS Polly. I am getting a 403 error stating {"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}. Here's my code,
import 'package:http/http.dart';
import 'package:sigv4/sigv4.dart';
void main() async {
final client = Sigv4Client(
keyId: <accessKEY>,
accessKey: <SecretAccessKEY>,
region: 'us-east-1',
serviceName: 'polly',
);
final request = client.request(
'https://polly.us-east-1.amazonaws.com/v1/speech',
method: 'POST',
body: jsonEncode({"OutputFormat": "mp3",
"VoiceId": "Salli",
"Text": "Hi, this is a request",
"TextType": "text"})
);
var responde = await post(request.url,headers: request.headers, body: request.body);
print(responde.body);
I had no luck using aws_polly_api as well. I am getting the error Unhandled Exception: 403 UnknownError: 403 with aws_polly_api. Here's the code I used:
import 'package:aws_polly_api/polly-2016-06-10.dart';
import 'package:http/http.dart' as http;
void main() async{
var credentials = new AwsClientCredentials(accessKey: <AccessKEY>, secretKey: <SecretAccessKEY);
var outputFormat1 = OutputFormat.mp3;
var text1 = "Hi, This is a request";
var voiceId1 = VoiceId.salli;
var textType1 = TextType.text;
var url = "https://polly.us-east-1.amazonaws.com/v1/speech";
var httpclient = new http.Client();
final service = Polly(region: 'us-east-1', credentials: credentials, client: httpclient, endpointUrl: url);
var resp = service.synthesizeSpeech(outputFormat: outputFormat1, text: text1, voiceId: voiceId1);
resp.then((value) => print(value));
}
Any help on how to get AWS Polly to work in flutter is highly appreciated. Also, if the input being sent is wrong, please help me in correcting it.
I have tried the same request with Postman to SynthesizeSpeech API and it worked...No extra headers were added except "'Content-type': 'application/json'". Just made a request with AWS signature and body in the form of raw json:
{
"OutputFormat": "mp3",
"VoiceId": "Salli",
"Text": "Hi, this is a request",
"TextType": "text"
}
It worked in postman.