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!