how I can change the voice synthesizer gender and age in C#?

不想你离开。 提交于 2019-11-26 14:14:01

问题


I would like to change the gender and age of the voice of System.Speech in c#. For example, a girl of 10 years but can not find any simple example to help me adjust the parameters.


回答1:


First, check which voices you have installed by enumerating the GetInstalledVoices method of the SpeechSynthesizer class, and then use SelectVoiceByHints to select one of them:

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



回答2:


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 ?




回答3:


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



回答4:


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)

Change VoiceGender
Change VoiceAge




回答5:


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!



来源:https://stackoverflow.com/questions/10881370/how-i-can-change-the-voice-synthesizer-gender-and-age-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!