First, we need to reference the
System.Speech
assembly from the application. From the Project menu, choose Add Reference. The from the .NET tab, highlight System.Speech
and choose OK.Declarations
Next, we need to declare and instantiate a
speech
object. The class isSystem.Speech.Synthesis.Speechsynthesizer
. This one class has enough properties and methods to speak a string
using the default language and voice of the OS. In Microsoft Windows Vista, the default voice is Microsoft Ana. protected void ibtnSpeaker_Click(object sender, ImageClickEventArgs e)
{
Thread t = new Thread(() =>
{
SpeechSynthesizer audio = new SpeechSynthesizer();
audio.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Senior); // to change VoiceGender and VoiceAge check out those links below
audio.Volume = 100; // (0 - 100)
audio.Rate = -1; // (-10 - 10)
audio.Speak(lblQuestionStart.Text);
});
t.Start();
}