Speech Synthesis Program in C Sharp Console application is what you write it would speak.
It’s a text to the voice conversion basic program.
Step No, 01: Create a new project in visual studio by pressing (ctrl + shift + N) Or follow
Go to File à New à Project… then click.
Choose the project type here you should choose Console.
First of all, before writing the speech program, we need to add the Speech Synthesizer reference in our project.
Right click on you references in solution explorer windows of the project.
Then a window popup and
We have added the Reference, but we don’t specify in our Program.cs namespace
So add the following.
using System.Speech.Synthesis;
Now it’s time to complete our basic program, but in this tutorial, we also write the entire loop based and user based program to wait unit user want to exit the program.
The output of the above program.
In the above, I enter the string that Hi! Junaid Ahmed welcome to our speech program. And then press enter the program return the audio sound of the above string.
Now expand the program for many time input until the user wants to exit.
using System; using System.Collections.Generic; using System.Linq; using System.Speech.Synthesis; using System.Text; using System.Threading.Tasks; namespace SpeechSynth { class Program { static void Main(string[] args) { Console.WriteLine("Welcome to Our Speech Program!"); SpeechSynthesizer speak = new SpeechSynthesizer(); string response = ""; do { //prompt to the user Console.WriteLine("Write something! "); speak.Speak(Console.ReadLine()); //for more execution Console.WriteLine("Do you want to continue ? y/n"); response = Console.ReadLine(); //User response if (response == "y" || response == "Y") { continue; } else { Console.WriteLine("Bye! You press n/N."); break; } } while (response == "y" || response == "Y"); //Wait untill user press any key to continue Console.ReadKey(); } } }
When I execute the program by pressing F5 the program’s output screen popup and wait to input the string so in my case I give the Hi! My name is Junaid Ahmed then press enter the program speak that line of code. Then it prompts that do you want to continue. I press y then program continue so until I press n program will continue to execute.