This Azure tutorial will discuss how to convert text to speech with Azure Cognitive Services.
Azure Text to Speech
Before discussing the actual functionality, we should know about Azure Speech Services.
Azure Speech Services
Well, here we will discuss an end-to-end tutorial on Azure Speech Services. Azure Speech Services provides you with the speech processing capability for your application easily. It helps the developer easily implement the application’s speech-processing capability with very little coding effort.
The Speech processing capability includes the following
- Speech to text: You can convert the speech to readable text with the help of the Azure Cognitive Speech API.
- Text to speech: We can convert the Text to audible speech easily with the help of the Azure Speech API.
- Speech translation: you can integrate speech translation easily into your apps using Azure cognitive services Speech API.
- Speaker recognition: Provides the ability to recognize people speaking based on their audio.
Before starting the actual functionality, we should be aware of the Prerequisites needed here.
Prerequisites
- You must have a valid Azure Subscription or a Valid Azure Account. If you don’t have one till now, create an Azure Free Account now.
- It would be best to have the Speech Service subscription and the Azure Subscription.
- Visual Studio 2019 needs to be installed on your local machine. If you don’t have it on your local machine, install Visual Studio 2019 now.
Assuming you have all the Prerequisites needed for the development activity, let’s begin the actual development process. The first step is creating the Azure Cognitive Services Speech API.
Create the Azure Cognitive Services Speech API
Follow the steps below to create the Azure Cognitive Services Speech API using the Azure Portal.
1. Log in to the Azure Portal (https://portal.azure.com/)
2. Then, search for ‘Speech’ and click on the search result ‘Speech’ under the Marketplace, as highlighted below.

3. On the Create window, you need to provide the following details.
- Name: You must provide a name for the Azure Cognitive Services Speech API.
- Subscription: You need to provide a valid subscription that you want to use to create the Speech Azure Cognitive Services.
- Location: You must provide a location for the Speech Azure Cognitive Services.
- Pricing tier: Select the Free F0 pricing tier, which is complimentary and can be used for the demo. You can click the ‘View full pricing details’ link to review all the price details and select one that meets your requirements.
- Resource group: You can select your existing resource group or create a new one by clicking on the Create new link if you don’t have any existing Resource groups.
Once you have provided all the above options, click the Create button to create the Speech Azure Cognitive Service.

On the screen below, click the Go to resource button to navigate to the Speech Azure Cognitive Service you created.

Now you can see the Cognitive Service you have created just now. Click on the Overview tab. On the Cognitive Service page, you can see the location for the Speech Cognitive Service page. You can note down the location for the Speech Cognitive Service that we need to use in the code in the steps below.

We need the key for the Speech Cognitive Service to use in our code. On the Cognitive Service page, click on the Keys and Endpoint link from the left navigation. Now, you can see the Key 1 or Key 2 option. Click the copy button to copy KEY 1 to the clipboard as highlighted below. The key value we will have to use in the code.
If you don’t want to use the old key, click the ReGenerate Key1 or ReGenerate Key2 button to generate a new one. To view the Key values, click the Show Keys button.

Now, we have completed our first step in the development activity. The next step is to create a console application and add the C# code to convert the Speech to text and text to Speech using Visual Studio 2019. Let’s create a console application.
Create a console application using Visual Studio 2019
Open Visual Studio 2019 from your local machine and click the Create a New Project button in the Get Started window.
Choose the Project template as Console App (.NET Framework) and click the Next button.

Provide the details below on the Configure your new project window
- Project Name: Provide a unique name for your console application.
- Location: Choose a location on your local machine to save your console application.
- Framework: Select the latest framework.
Finally, click on the Create button to create the console application.

You can see that the project was created successfully without any issues.

Installing the Speech SDK
Next, we will work with the Azure Speech service. We need to add a NuGet package named Microsoft.CogntiveServices.Speech. To add the NuGet package to your project, follow the steps below
Right-click on the Project and then click on the Manage NuGet Package Link as shown below