Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Computer Talker with C#

3.45/5 (44 votes)
9 Oct 2024CPOL 59.3K   981  
Write a program to make your computer talk for you.

Introduction

Write a simple program to make your computer talk for you.

Using the Code

  1. Add a textbox named 'txtWords' to a form.
  2. Add a button named 'btnSpeak' to a form.
  3. Add a reference to System.Speech.
  4. In the form's code-behind, add:
    C#
    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();
      }
     }
    }
  5. Run. Text entered into the textbox will be spoken by the computer.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)