.net - AWS Polly 集成 SDK

标签 .net amazon-web-services amazon-polly

我刚刚看到关于 Amazon Polly text-to-speech service 的公告.我可以在 AWS 控制台中访问该服务,但找不到任何集成点。控制台中没有任何链接可以访问 API/SDK。

v3 documentation for the AWS .NET SDK也不包含 Polly 的文档。

是否有适用于 .NET 和 Amazon Polly 的 SDK?

最佳答案

你检查过这个link吗? ? 目前,在 Amazon Polly 开发人员指南 ( pdf/html ) 中,您可以找到 python、android、iOS 的示例。安装 SDK 后,您可以找到 C:\Program Files (x86)\AWS SDK for .NET\bin\Net45\AWSSDK.Polly.dll,其中包含使用 Polly 的所有类。

这是我刚刚玩过的一个简单示例:

    public static void Main(string[] args)
    {

        AmazonPollyClient client = new AmazonPollyClient();

        // 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();
    }

它返回带有您指定文本的 mp3 编码音频文件。

关于.net - AWS Polly 集成 SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40922581/

相关文章:

c# - .net 4.0 中的 MemoryCache 与 ObjectCache 有什么区别?

azure - amazon 或 heroku 是否提供 worker 角色服务

amazon-web-services - 允许 AWS Lex 接受任何用户输入

.net - 将 XML 文件转换为 MS SQL Server DB

c# - 进程未在程序结束时终止

amazon-web-services - 我们可以在 AWS::CloudFormation::Init 中收集实例元数据吗

aws-lambda - 使用 AWS Polly 的 PCM 格式

swift - AWS Polly - 突出显示特殊字符

javascript - s3 上传音频文件但无法播放。如何上传音频流到s3?

c# - .NET 4 异步 WebRequest 与多线程