无法通过 Amazon Polly 进行身份验证

Fails to authenticate with Amazon Polly

我一直在尝试制作一个关于如何使用 polly 的 hello wold 示例 (https://aws.amazon.com/polly/)

我不想下载任何库。我只想使用我的凭据向亚马逊网络服务发出一个简单的 http 请求并取回音频。这可能吗?

我已经在 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

您需要为您的凭据调用指定一个区域作为第三个参数 - 即 RegionEndpoint.USEast1。

I.E:

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

(与免费账号无关)