Sample Program: Text to Voice

Sample Program: Text to Voice

Author: Lilian Dyer

To learn the anatomy of a C# program. To learn about the files the IDE creates to run a program. To study some sample code to produce voice from text.

You will use Microsoft Visual C# Express 2010 to write this program. This Windows Forms Application sample code actually runs. It uses the new namespace System.Speech.Synthesis to produce voice from text. You will create a form or GUI to interact with the user where the user will enter any text and when pressing the "Speak to me!!" button the user will hear the phrase or sentence she entered.

See More
Introduction to Psychology

Analyze this:
Our Intro to Psych Course is only $329.

Sophia college courses cost up to 80% less than traditional courses*. Start a free trial now.


A note on Methods

What is the difference between parameters and arguments? They are called parameters when they are defined as values that can be passed to a method.  They are called arguments when a method is called and you pass values to it.

Example of Method definition:

public static int BlahBlahBlah(string thingToSay, int numberOfTimes)


   //  statements go here...

  return value



Example of calling this same method:

int size = BlahBlahBlah("Hello World!", 3);

This method is passing two arguments: 1) The first argument is "Hello World!" of type string; 2) The second argument is a number 3 of type int.

MessageBox.Show("This is an argument");

When you call a method the arguments must be the same type as the types of the parameters. The number of arguments depends on the number of parameters. So a method could have any number of parameters or no parameters at all.

How to Add the System.Speech

  • Go to the Solution Explorer window
  • Right Click on References
  • Choose Add Reference...
  • Choose the tab .NET
  • Scroll down until you find System.Speech
  • Click OK

The Anatomy of a C# Program


This is the program running...