【问题标题】:Fails to authenticate with Amazon Polly无法通过 Amazon Polly 进行身份验证
【发布时间】:2017-08-31 14:24:03
【问题描述】:

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

我不想下载任何库。我只想用我的凭据向亚马逊网络服务发出一个简单的 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

【问题讨论】:

  • it does not work 不是有效的问题陈述。更具体。
  • IAM 用户是否拥有允许其使用 Polly 的权限策略?
  • 是的,它可以完全访问 Polly。我刚刚注册了亚马逊网络服务。会不会是因为我有免费帐户?

标签: c# amazon-web-services text-to-speech amazon-polly


【解决方案1】:

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

IE:

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

(与免费帐户无关。)

【讨论】:

    猜你喜欢
    • 2012-04-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    相关资源
    最近更新 更多