Click here to Skip to main content
16,014,765 members
Articles / Programming Languages / C#
Tip/Trick

Computer Talker with C#

Rate me:
Please Sign up or sign in to vote.
4.00/5 (37 votes)
28 Sep 2024CPOL 51.5K   745   30   31
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)


Written By
Teraten
United States United States
+ Teraten
Plan your next win with Teraten.

Comments and Discussions

 
QuestionWell it works ! Pin
Gluups12hrs 24mins ago
Gluups12hrs 24mins ago 
AnswerRe: Well it works ! Pin
Johan Blanckaert5hrs 46mins ago
Johan Blanckaert5hrs 46mins ago 
QuestionComputer talker with c# Pin
Johan Blanckaert1-Oct-24 0:22
Johan Blanckaert1-Oct-24 0:22 
AnswerRe: Computer talker with c# Pin
Gluups13hrs 30mins ago
Gluups13hrs 30mins ago 
SuggestionAlternative? Pin
dandy7230-Sep-24 4:59
dandy7230-Sep-24 4:59 
GeneralMy vote of 5 Pin
WeaselWes15-Nov-14 5:16
WeaselWes15-Nov-14 5:16 
QuestionShort, Sweet and to the Point Pin
StevieLee14-Nov-14 4:12
StevieLee14-Nov-14 4:12 
AnswerRe: Short, Sweet and to the Point Pin
Teraten14-Nov-14 5:36
Teraten14-Nov-14 5:36 
AnswerRe: Short, Sweet and to the Point Pin
User 1106097915-Nov-14 0:38
User 1106097915-Nov-14 0:38 
QuestionWhy the class level SpeechSynthesizer variable? Pin
spencepk13-Nov-14 9:53
spencepk13-Nov-14 9:53 
AnswerRe: Why the class level SpeechSynthesizer variable? Pin
Teraten13-Nov-14 11:12
Teraten13-Nov-14 11:12 
GeneralMy vote of 2 Pin
Tammam Koujan12-Nov-14 21:32
professionalTammam Koujan12-Nov-14 21:32 
GeneralRe: My vote of 2 Pin
aeastham13-Nov-14 2:23
aeastham13-Nov-14 2:23 
GeneralRe: My vote of 2 Pin
Tammam Koujan13-Nov-14 3:22
professionalTammam Koujan13-Nov-14 3:22 
GeneralRe: My vote of 2 Pin
Gluups13hrs 23mins ago
Gluups13hrs 23mins ago 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun12-Nov-14 17:39
Humayun Kabir Mamun12-Nov-14 17:39 
GeneralMy vote of 1 Pin
emrea12-Nov-14 8:56
emrea12-Nov-14 8:56 
GeneralMy vote of 5 Pin
Mahsa Hassankashi12-Nov-14 8:38
Mahsa Hassankashi12-Nov-14 8:38 
GeneralMy vote of 5 Pin
User 1106097912-Nov-14 8:15
User 1106097912-Nov-14 8:15 
GeneralRe: My vote of 5 Pin
Teraten12-Nov-14 8:26
Teraten12-Nov-14 8:26 
GeneralMy vote of 4 Pin
newton.saber12-Nov-14 7:48
newton.saber12-Nov-14 7:48 
GeneralRe: My vote of 4 Pin
Teraten12-Nov-14 8:27
Teraten12-Nov-14 8:27 
Thumbs Up | :thumbsup: Thanks! Thumbs Up | :thumbsup:
We can write a "hello, world" that actually says "hello".
SuggestionNice tip! Pin
Afzaal Ahmad Zeeshan12-Nov-14 7:46
professionalAfzaal Ahmad Zeeshan12-Nov-14 7:46 
GeneralMy vote of 2 Pin
Mladen Borojevic19-Mar-14 23:02
professionalMladen Borojevic19-Mar-14 23:02 
QuestionJust basic stuff :) Pin
MaskedDev19-Mar-14 6:20
professionalMaskedDev19-Mar-14 6:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.