Compartir a través de


Speak the Contents of a String

A simple way to generate synthesized speech is to create a SpeechSynthesizer instance, and then call the synthesizer’s Speak(String) method, passing the string to be spoken as an argument.

The following example shows the Main method of a class in a console application.

When Main begins to run, a SpeechSynthesizer instance named s is created, and then the Speak(String) method on s is called. The string literal to be spoken is passed in the call.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;

namespace SimpleSpeak
{
  class Program
  {
    static void Main(string[] args)
    {
      SpeechSynthesizer s = new SpeechSynthesizer();
      s.Speak("Hello. My name is Microsoft Anna.");

    }
  }
}