改变文本到语音的性别

时间:2014-06-30 15:50:11

标签: c# .net text-to-speech

我想为我的互动式训练集制作一个文本到语音的程序。我使用System.Speech库,但声音总是女性。我想用一些男性的声音读一些句子,一些用女性的声音读。 (这两个声音是我唯一需要的声音。)

我使用的是Windows 8 Pro和Visual Studio 2010.我只能看到一个语音包,即Microsoft Zira Desktop。

我的代码如下。如何配置男声的使用?

SpeechSynthesizer synth = new SpeechSynthesizer();
synth.Rate = 1;
synth.Volume = 100;
synth.SelectVoiceByHints(VoiceGender.Male,VoiceAge.Adult);
synth.SpeakAsync(label18.Text);

1 个答案:

答案 0 :(得分:6)

您首先需要知道安装了哪些语音,您可以通过SpeechSynthesizer类的GetInstalledVoices方法来完成此操作: http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.getinstalledvoices.aspx

一旦确定安装了男声,那么您只需按SelectVoiceByHints切换即可 看到: http://msdn.microsoft.com/en-us/library/ms586877

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);
}

有关进一步说明,请参阅此处: how I can change the voice synthesizer gender and age in C#?