C# Set voice in Text to Speech
-
Hi, How do I set the voice in Text to Speech in C#? I have a toolStripMenu that I load the voices into. Then when one is chosen, I want it to use that voice. Haven't been able to figure set the voice to the chosen name. Thanks.
private void Get_Voices()
{
ISpeechObjectTokens voices = objSpeech.GetVoices("", "");foreach (ISpeechObjectToken v in voices) { ts\_Menu = new ToolStripMenuItem(); v\_name = v.GetDescription(0); ts\_Menu.Text = v\_name; ts\_Menu.CheckOnClick = true; voicesToolStripMenu.DropDownItems.Add(ts\_Menu); ts\_Menu.Click += voice\_Menu\_Click; }
}
private void voice_Menu_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = sender as ToolStripMenuItem;
foreach (ToolStripMenuItem tempItemp in voicesToolStripMenu.DropDownItems)
{if (tempItemp == item) { tempItemp.Checked = true; } else { tempItemp.Checked = false; } } choosen\_voice = sender.ToString();
}
private void Speak(string txt)
{SpVoice objSpeech = new SpVoice(); objSpeech.Speak(txt, SpeechVoiceSpeakFlags.SVSFlagsAsync); objSpeech.WaitUntilDone(Timeout.Infinite);
}
-
Hi, How do I set the voice in Text to Speech in C#? I have a toolStripMenu that I load the voices into. Then when one is chosen, I want it to use that voice. Haven't been able to figure set the voice to the chosen name. Thanks.
private void Get_Voices()
{
ISpeechObjectTokens voices = objSpeech.GetVoices("", "");foreach (ISpeechObjectToken v in voices) { ts\_Menu = new ToolStripMenuItem(); v\_name = v.GetDescription(0); ts\_Menu.Text = v\_name; ts\_Menu.CheckOnClick = true; voicesToolStripMenu.DropDownItems.Add(ts\_Menu); ts\_Menu.Click += voice\_Menu\_Click; }
}
private void voice_Menu_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = sender as ToolStripMenuItem;
foreach (ToolStripMenuItem tempItemp in voicesToolStripMenu.DropDownItems)
{if (tempItemp == item) { tempItemp.Checked = true; } else { tempItemp.Checked = false; } } choosen\_voice = sender.ToString();
}
private void Speak(string txt)
{SpVoice objSpeech = new SpVoice(); objSpeech.Speak(txt, SpeechVoiceSpeakFlags.SVSFlagsAsync); objSpeech.WaitUntilDone(Timeout.Infinite);
}
See here: Speech - Text-To-Speech Synthesis in .NET | Microsoft Docs[^] - it includes sample code which does that.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
See here: Speech - Text-To-Speech Synthesis in .NET | Microsoft Docs[^] - it includes sample code which does that.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
I see. Thanks!
-
I see. Thanks!
You're welcome - but please try the official documentation first next time! :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!