Mohanapriya R Mohanapriya R
Updated date May 27, 2024
In this article, we will explore Text-to-Speech in C#. Learn how to implement this in C# with examples and explanations.

How to Convert Strings to Speech using C#?

In C#, you can use the built-in System.Speech.Synthesis namespace, which provides the necessary tools for converting strings into speech. We ensure that we have the required libraries and dependencies in place.

We can use SpeechSynthesizer class from the System.Speech.Synthesis namespace to convert the strings to speech.

using System;
using System.Speech.Synthesis;

class TextToSpeechConverter
{
    static void Main()
    {
        Console.Write("Enter the text you want to convert to speech: ");
        string inputText = Console.ReadLine();

        // Creating a SpeechSynthesizer instance
        using (SpeechSynthesizer synth = new SpeechSynthesizer())
        {
            // Converting the input text to speech
            synth.Speak(inputText);
        }
    }
}
  • We prompt the user to input the text they want to convert into speech.
  • We create an instance of SpeechSynthesizer.
  • The Speak method is then used to convert the input text into speech.

Output:

Let's say the user inputs:

Enter the text you want to convert to speech:
Hello, this is Text-to-Speech in C#.

The program will then output the spoken version of the entered text:

Hello, this is Text-to-Speech in C#.

Comments (0)

There are no comments. Be the first to comment!!!