我想在c#中更改System.Speech
的声音的性别和年龄。例如,一个10岁的女孩却找不到任何简单的例子来帮助我调整参数。
答案 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)
http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voiceage.aspx http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voicegender.aspx
你看过这个吗?
答案 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
}
}
}
答案 4 :(得分:0)
这些年龄和性别实际上没用。如果您的窗口中安装了许多声音,则可以通过这些参数调用特定的声部。否则,它只是假的!