If you haven’t checked out Amazon’s new Polly (Text-to-Speech (TTS) cloud service) it does produce some pretty great, life-like audio. Below is a quick sample on how you can feed some text to Polly, and get an MP3 file with it. I don’t cover all of the install options of the AWS Toolkit for Visual Studio / .Net, but it’s pretty simple. (listen to this text here)
Below is some code:
AmazonPollyClient pc = new AmazonPollyClient(); SynthesizeSpeechRequest sreq = new SynthesizeSpeechRequest(); sreq.Text = "Your Sample Text Here"; sreq.OutputFormat = OutputFormat.Mp3; sreq.VoiceId = VoiceId.Amy; SynthesizeSpeechResponse sres = pc.SynthesizeSpeech(sreq); using (var fileStream = File.Create(@"c:\yourfile.mp3")) { sres.AudioStream.CopyTo(fileStream); fileStream.Flush(); fileStream.Close(); }
Also make sure you have the below included:
using Amazon.Polly;
using Amazon.Polly.Model;
And these 2 NuGet packages added to your project:
This only scratches the surface of what Polly can do. Between streaming, SSML, Lexicons and more at a great price, I think we’ll be seeing more applications use this.
chris, i love you. thank you so much
LikeLiked by 1 person
🙂
LikeLike
Actually, you should have covered the setting of the .NET Project because it is not that simple at all.
LikeLike
Thanks for this man, I needed this tutorial. The only thing is that I had to supply an Amazon.RegionEndpoint object to the constructor in order for this to work.
LikeLiked by 1 person
Glad it was helpful!
LikeLike