Using the Code
- Add a textbox named '
txtWords
' to a form. - Add a button named '
btnSpeak
' to a form. - Add a reference to
System.Speech
. - In the form's code-behind, add:
using System.Windows.Forms; using System.Speech.Synthesis; namespace Sample { public partial Class Form1: Form { public SpeechSynthesizer _synthesizer; private void btnSpeak_Click(object sender, EventArgs e) { _synthesizer = new SpeechSynthesizer(); var words = txtWords.Text; _synthesizer.Speak(Words); } public Form1() { InitializeComponent(); } } }
- Run. Text entered into the textbox will be spoken by the computer.