如何在 C# 中更改语音合成器的性别和年龄?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10881370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how I can change the voice synthesizer gender and age in C#?
提问by Pablo Gonzalez
I would like to change the gender and age of the voice of System.Speechin c#. For example, a girl of 10 years but can not find any simple example to help me adjust the parameters.
我想改变System.Speechc#中声音的性别和年龄。例如,一个10岁的女孩却找不到任何简单的例子来帮助我调整参数。
采纳答案by Groo
First, check which voices you have installed by enumerating the GetInstalledVoicesmethod of the SpeechSynthesizerclass, and then use SelectVoiceByHintsto select one of them:
首先通过枚举类的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);
}
回答by Pierre Pellegrino Milza
http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voiceage.aspxhttp://msdn.microsoft.com/en-us/library/system.speech.synthesis.voicegender.aspx
http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voiceage.aspx http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voicegender.aspx
Did you take a look at this ?
你看看这个吗?
回答by Razib Ali
These age and gender is actually of no use. If you have many voices installed in your windows, then you may call specific voices by these parameters. Otherwise, its simply fake!
这些年龄和性别实际上是没有用的。如果您的窗口中安装了许多声音,那么您可以通过这些参数调用特定的声音。否则,它只是假的!
回答by Pran
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
}
}
}
- It'll be better choice to use "SpeakAsync" because when "Speak" function is executing/running none of other function will work until it finishes it's work (personally recommended)
- 使用“SpeakAsync”会是更好的选择,因为当“Speak”功能正在执行/运行时,其他功能都不会工作,直到它完成它的工作(个人推荐)
回答by Draxy07
first you need to intialise the reference speech using the add reference.
首先,您需要使用添加参考来初始化参考语音。
then create an event handler for the speak started then you can edit the paramemters inside that handler.
然后为开始的发言创建一个事件处理程序,然后您可以编辑该处理程序中的参数。
in the handler is where you can change the voice and age using the
在处理程序中,您可以使用
synthesizer.SelectVoiceByHints(VoiceGender.Male , VoiceAge.Adult);

