In this step by step demo, we are going to learn how to turn text into speech using Microsoft Azure.
For that, we are going to use Azure Neural Text to speech service.
We can turn the text into human speech in many languages and voices.
Let us go ahead and see how we can do that.
Go to Azure portal and search for Speech. You will find this service. Click create. This is a Cognitive Speech service that includes API endpoints such as Text to speech service.
Put it in a resource group. Choose a region. Give the service a name and choose the free tier. Create it.
This is what the Speech service would look like. Go to keys and endpoint.
Copy the access key 1 and location of the service. We are going to need that later.
Copy the access key 1 and location of the service. We are going to need that later.
Next, go to NuGet packages and install Microsoft.CognitiveServices.Speech.
Back in the Program.cs file, add this namespace.
Then down below, create a new config with the access key and the location that we saw in the portal.
Next, use that same config to create a speech synthesizer.
And then we invoke the SpeakTextAsync with a text that we want to be turned into speech.
When you run the application, you will get the desired output. Of course since the output is an audio one, I can’t show that to you here.
These are the default settings that we are using right now.
This means that the service detects the language of the input, and uses the default voice to synthesize it. The language that it uses it US English for this.
Add this line of code and now it will give the output in British English.
Run the application again and you will see the difference in the output.
Similarly, you can use different voices as well. Add this line of code and the run the application to see the output.
If you add this line of code, it will give you an output in the form of a wav file.
That is it for this amazing step by step demo. I am sure you must be excited to try this yourself.