如何在C#中改变语音合成器的性别和年龄?

时间:2012-06-04 12:35:25

标签: c# speech synthesizer

我想在c#中更改System.Speech的声音的性别和年龄。例如,一个10岁的女孩却找不到任何简单的例子来帮助我调整参数。

5 个答案:

答案 0 :(得分:20)

首先,通过枚举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);
}

答案 1 :(得分:11)

答案 2 :(得分:3)

首先,您需要使用添加引用初始化参考语音。

然后为开始讲话创建一个事件处理程序,然后您可以编辑该处理程序中的参数。

处理程序中的

可以使用

更改语音和年龄
synthesizer.SelectVoiceByHints(VoiceGender.Male , VoiceAge.Adult);

答案 3 :(得分:1)

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"是更好的选择。因为"说话"功能正在执行/运行其他任何功能都不起作用,直到完成它的工作(个人推荐)

Change VoiceGender
Change VoiceAge

答案 4 :(得分:0)

这些年龄和性别实际上没用。如果您的窗口中安装了许多声音,则可以通过这些参数调用特定的声部。否则,它只是假的!