我正在使用https://pub.dev/packages/sigv4 dart 包向 AWS Polly 发出请求。我收到 403 错误,说明{"message":"我们计算的请求签名与您提供的签名不匹配。请检查您的 AWS 秘密访问密钥和签名方法。有关详细信息,请参阅服务文档。"}。这是我的代码,
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);
我也没有运气使用 aws_polly_api。我收到错误Unhandled Exception: 403 UnknownError: 403 with aws_polly_api。这是我使用的代码:
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));
}
非常感谢有关如何让 AWS Polly 在 Flutter 中工作的任何帮助。另外,如果发送的输入错误,请帮助我更正它。
我已经尝试使用 Postman 向 SynthesizeSpeech API 发出相同的请求,并且它起作用了......除了“'Content-type':'application/json'”之外,没有添加额外的标题。刚刚以原始 json 的形式使用 AWS 签名和正文发出请求:
{
"OutputFormat": "mp3",
"VoiceId": "Salli",
"Text": "Hi, this is a request",
"TextType": "text"
}
它在邮递员中工作。