Today
I am going to explain how we can select tone when we are converting text to
speech.
In
the previous article Converting Text To Speech in Windows Forms I have demonstrated the way we can get audio output to the
typed text in windows forms. Now I’ll demonstrate how we can select the tone
that reads the given text.
First
drag a combo box onto the form. Then add two values into the combo box i.e.
Female and Male.
In
the code page write a condition in the button click event. Check which of the
following values are selected? The condition can be as follows
if (comboBox1.SelectedItem == "Female")
If
the condition is satisfied then the female voice is selected.
Here
we will write the Speaker hints as follows
reader.SelectVoiceByHints(VoiceGender.Female);
If
the selected combo box item is male then male voice is selected.
reader.SelectVoiceByHints(VoiceGender.Male);
Now
the entire code altogether is
using System.Speech;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace NameSpace
{
public partial class TextToSpeech : Form
{
SpeechSynthesizer
reader;
public
TextToSpeech()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
if
(textBox1.Text != "")
{
if
(comboBox1.SelectedItem == "Female")
{
reader = new SpeechSynthesizer();
reader.SelectVoiceByHints(VoiceGender.Female);
reader.SpeakAsync(textBox1.Text);
}
else
if (comboBox1.SelectedItem == "Male")
{
reader = new SpeechSynthesizer();
reader.SelectVoiceByHints(VoiceGender.Male);
reader.SpeakAsync(textBox1.Text);
}
}
}
}
}
No comments:
Post a Comment