Click here to Skip to main content
16,014,871 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 22mins ago
Gluups12hrs 22mins ago 
AnswerRe: Well it works ! Pin
Johan Blanckaert5hrs 44mins ago
Johan Blanckaert5hrs 44mins 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 28mins ago
Gluups13hrs 28mins ago 
SuggestionAlternative? Pin
dandy7230-Sep-24 4:59
dandy7230-Sep-24 4:59 
I'm not sure how I ended up here...probably because the article was marked as having been updated yesterday.

In any case, the speech engine this relies on is now very, very old. The text-to-speech engine built into Edge (the Read Aloud function) is leaps and bounds better than that, and I've been reliably informed it's a completely different library that has nothing to do with this one.

It's not clear to me however whether this newer engine has a public API. It would be interesting to know if it does, and how to use it. I get the impression MS has really only developed it to work with their browser, but surely there's gotta be some reusable interface hiding somewhere in there.

If that sort of thing still interests you, it might be worth trying to dig this up and putting together an article that demonstrates its use.

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 21mins ago
Gluups13hrs 21mins 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 
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.