我如何在C#中改变语音合成器的性别和年龄?
我想在c#中改变System.Speech
声音的性别和年龄。 例如,一个10岁的女孩却找不到任何简单的例子来帮助我调整参数。
首先,通过枚举SpeechSynthesizer
类的GetInstalledVoices
方法检查已安装的SpeechSynthesizer
,然后使用SelectVoiceByHints
选择其中一个:
using (SpeechSynthesizer synthesizer = new SpeechSynthesizer()) { // show installed voices foreach (var v in synthesizer.GetInstalledVoices().Select(v => v.VoiceInfo)) { Console.WriteLine("Name:{0}, Gender:{1}, Age:{2}", v.Description, v.Gender, v.Age); } // select male senior (if it exists) synthesizer.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Senior); // select audio device synthesizer.SetOutputToDefaultAudioDevice(); // build and speak a prompt PromptBuilder builder = new PromptBuilder(); builder.AppendText("Found this on Stack Overflow."); synthesizer.Speak(builder); }
http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voiceage.aspx http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voicegender.aspx
你看看这个吗?
首先,您需要使用添加引用初始化引用语音。
然后为开始讲话创建一个事件处理程序,然后您可以编辑该处理程序中的参数。
在处理程序中,您可以使用。更改语音和年龄
synthesizer.SelectVoiceByHints(VoiceGender.Male , VoiceAge.Adult);
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Speech.Synthesis; // first import this package namespace textToSpeech { public partial class home : Form { public string s = "pran"; // storing string (pran) to s private void home_Load(object sender, EventArgs e) { speech(s); // calling the function with a string argument } private void speech(string args) // defining the function which will accept a string parameter { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); synthesizer.SelectVoiceByHints(VoiceGender.Male , VoiceAge.Adult); // to change VoiceGender and VoiceAge check out those links below synthesizer.Volume = 100; // (0 - 100) synthesizer.Rate = 0; // (-10 - 10) // Synchronous synthesizer.Speak("Now I'm speaking, no other function'll work"); // Asynchronous synthesizer.SpeakAsync("Welcome" + args); // here args = pran } } }
- 使用“SpeakAsync”是更好的选择,因为当“Speak”function正在执行/运行时,其他任何function都无法工作,直到完成它的工作(个人推荐)
改变VoiceGender
改变VoiceAge
这些年龄和性别实际上没有用。 如果您的窗口中安装了许多声音,则可以通过这些参数调用特定的声部。 否则,它只是假的!