// AWS credentials
string _accessKey = "myaccesskey";
string _secretKey = "mysecret";
string _region = "us-east-1";
PollyRequest pollyRequest = new PollyRequest
{
OutputFormat = "json",
Text = "Hello, this is a sample text to be synthesized.",
VoiceId = "Joanna",
SpeechMarkTypes = new[] { "viseme", "word" },
LexiconNames = new string[] { },
SampleRate = "22050",
TextType = "text",
LanguageCode = "en-US"
};
// Convert the object to JSON
string _json = JsonConvert.SerializeObject(pollyRequest);
var signer = new Aws4RequestSigner.AWS4RequestSigner(_accessKey, _secretKey);
var content = new StringContent(_json, Encoding.UTF8, "application/json");
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(apiUrl),
Content = content
};
I get forbidden error when trying to request audio data from amazon poly: "https://polly.us-east-1.amazonaws.com/v1/speech";
// Specify the URL string apiUrl = "https://polly.us-east-1.amazonaws.com/v1/speech";
// AWS credentials string _accessKey = "myaccesskey"; string _secretKey = "mysecret"; string _region = "us-east-1"; PollyRequest pollyRequest = new PollyRequest { OutputFormat = "json", Text = "Hello, this is a sample text to be synthesized.", VoiceId = "Joanna", SpeechMarkTypes = new[] { "viseme", "word" }, LexiconNames = new string[] { }, SampleRate = "22050", TextType = "text", LanguageCode = "en-US" };
// Convert the object to JSON string _json = JsonConvert.SerializeObject(pollyRequest);
var signer = new Aws4RequestSigner.AWS4RequestSigner(_accessKey, _secretKey); var content = new StringContent(_json, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(apiUrl), Content = content };
request = await signer.Sign(request, "Polly", _region);
var client = new HttpClient(); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode();