23

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.

demonplus
  • 5,613
  • 12
  • 49
  • 68
Pablo Gonzalez
  • 673
  • 2
  • 10
  • 24

5 Answers5

25

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);
}
vgru
  • 49,838
  • 16
  • 120
  • 201
  • If speaker is a woman yet, means that I dont have male voice in my system, so I need to download it? – Pablo Gonzalez Jun 04 '12 at 13:09
  • @Pablo: that's correct, although, to tell you the truth, I have no clue where to download them from. [This MSDN page](http://www.microsoft.com/en-us/download/details.aspx?id=27224) looks like it has some additional voices, but I never used any of them. – vgru Jun 04 '12 at 13:17
  • Ok, change voice properties is just a question I had time ago, because I wanna know more about speech namespace. I will go to find a little girl voice if really exist hahah thanks again – Pablo Gonzalez Jun 04 '12 at 13:21
12

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 ?

4

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);
Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
Draxy07
  • 81
  • 7
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
                }       
         }
    }
  • 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

Pran
  • 1,817
  • 23
  • 23
0

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!

Razib Ali
  • 300
  • 1
  • 4
  • 11