1
我一直努力讓自己在如何使用波利(https://aws.amazon.com/polly/)失敗
我不想下載任何庫一個Hello Wold的例子與亞馬遜波利進行身份驗證。我只是想用我的憑據做一個簡單的http請求來獲得amazon web服務器並獲取音頻。那可能嗎?
我已經創建了IAM用戶,它看起來像這樣:
這是我迄今爲止,並沒有將文本轉換爲語音。我認爲問題是驗證。 :/
static void Main(string[] args)
{
var accessKeyId = @"I place in here my access key";
var secretKey = @"I place in here my secret key";
//Amazon.Runtime.AWSCredentials credentials = new
AmazonPollyClient client = new AmazonPollyClient(accessKeyId, secretKey);
// Create describe voices request.
DescribeVoicesRequest describeVoicesRequest = new DescribeVoicesRequest();
// Synchronously ask Amazon Polly to describe available TTS voices.
DescribeVoicesResponse describeVoicesResult = client.DescribeVoices(describeVoicesRequest);
List<Voice> voices = describeVoicesResult.Voices;
// Create speech synthesis request.
SynthesizeSpeechRequest synthesizeSpeechPresignRequest = new SynthesizeSpeechRequest();
// Text
synthesizeSpeechPresignRequest.Text = "Hello world!";
// Select voice for synthesis.
synthesizeSpeechPresignRequest.VoiceId = voices[0].Id;
// Set format to MP3.
synthesizeSpeechPresignRequest.OutputFormat = OutputFormat.Mp3;
// Get the presigned URL for synthesized speech audio stream.
var presignedSynthesizeSpeechUrl = client.SynthesizeSpeechAsync(synthesizeSpeechPresignRequest).GetAwaiter().GetResult();
using (FileStream output = File.OpenWrite("hello_world.mp3"))
{
presignedSynthesizeSpeechUrl.AudioStream.CopyTo(output);
}
Console.Read();
}
請注意這個例子編譯我不得不添加的NuGet包AWSSDK.Polly
'它沒有work'不是一個有效的問題陳述。更加詳細一些。 – tnw
IAM用戶是否有允許其使用Polly的權限策略? –
是的,它可以完全訪問Polly。我剛剛註冊了亞馬遜網絡服務。難道是因爲我有一個免費賬戶? –