Convert Text to Speech in .NET [C#]

Text to Speech

In .NET it is very easy to convert a given text into a Speech which can be heard from the speaker (provided it is connected to the machine). The process is very simple and is defined in the following steps (NOTE: the following code has been written for Windows Form):-

    • Add the reference of System.Speech

 

    • Add the reference of Microsoft Speech Object Library from the COM.

 

    • This is what I have designed as the user Interface for this Program

 

    • Now on the Click Event of the button Text to Speech add the following code (SpeechSynthesizer Class is defined within the namespace using System.Speech.Synthesis)
      
      SpeechSynthesizer synths = new SpeechSynthesizer();
      synths.SpeakAsync(txtSpeech.Text);
      
      

 

  • Finally, run the application and the text that you will type in the textbox can be heard from an attached speaker once the button Text to Speech is clicked.

SpeechSynthesizer provides access to the functionality of an installed a speech synthesis engine. More info can be found here