Search code examples
.netamazon-web-servicesamazon-polly

AWS Polly Integration SDKs


I just came across the announcement about Amazon Polly text-to-speech service. I am able to access the service in the AWS console, but I cannot find any integration points. There aren't any links in the console to access APIs / SDKs.

The v3 documentation for the AWS .NET SDK doesn't include docs for Polly either.

Are there SDKs for .NET, for Amazon Polly?


Solution

  • Have you checked this link? Currently, in Amazon Polly Developer Guide (pdf / html) you can find examples for python, android, iOS. After installing SDK you can find C:\Program Files (x86)\AWS SDK for .NET\bin\Net45\AWSSDK.Polly.dll that contains all the classes to use Polly.

    Here is a simple example I've just played with:

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

    It returns mp3 encoded audio file with the text you specify.