失败

2017-04-05 97 views
1

我一直努力让自己在如何使用波利(https://aws.amazon.com/polly/失败

我不想下载任何库一个Hello Wold的例子与亚马逊波利进行身份验证。我只是想用我的凭据做一个简单的http请求来获得amazon web服务器并获取音频。那可能吗?

我已经创建了IAM用户,它看起来像这样:

enter image description here

这是我迄今为止,并没有将文本转换为语音。我认为问题是验证。 :/

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

+3

'它没有work'不是一个有效的问题陈述。更加详细一些。 – tnw

+0

IAM用户是否有允许其使用Polly的权限策略? –

+0

是的,它可以完全访问Polly。我刚刚注册了亚马逊网络服务。难道是因为我有一个免费账户? –

回答

2

你需要知道你叫凭据作为第三个参数指定一个区域 - 即RegionEndpoint.USEast1。

即:

AmazonPollyClient client = new AmazonPollyClient("AKI5ZLVN6QXO123OJA", "4sYnPuAzMk/k07JA456728VbTpX4F5/FAKEGDiAKm", RegionEndpoint.USEast1); 

(它无关,与它是一个免费帐户)