Computer Talker with C# z

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:
    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.

你可能感兴趣的:(with)