2012-06-04 14 views

Respuesta

16

primer lugar, compruebe las voces que se ha instalado enumerando el método de la clase SpeechSynthesizerGetInstalledVoices, y luego usar SelectVoiceByHints para seleccionar uno de ellos:

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

Si el altavoz es una mujer aún, significa que no tengo voz masculina en mi sistema, ¿entonces debo descargarlo? –

+0

@Pablo: eso es correcto, aunque, a decir verdad, no tengo ni idea de dónde descargarlos. [Esta página de MSDN] (http://www.microsoft.com/en-us/download/details.aspx?id=27224) parece que tiene algunas voces adicionales, pero nunca las usé. – Groo

+0

Ok, cambiar las propiedades de voz es solo una pregunta que tuve hace tiempo, porque quiero saber más sobre el espacio de nombres de voz. Iré a buscar una pequeña voz de niña si realmente existe jaja gracias de nuevo –

0

Estos edad y el sexo es en realidad de ninguna utilidad. Si tienes muchas voces instaladas en tus ventanas, entonces puedes llamar voces específicas por estos parámetros. De lo contrario, es simplemente falso!

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 
       }  
     } 
    } 
  • Será mejor opción para usar "SpeakAsync" porque cuando "Habla" función se ejecuta/marcha ninguno de otra función funcionará hasta que termine su trabajo (recomendado personalmente)

Change VoiceGender
Change VoiceAge

0

primero que hay que intialise la voz de referencia mediante la referencia complemento.

a continuación, cree un controlador de eventos para la conversación iniciada, luego puede editar los parámetros dentro de ese controlador.

en el controlador es donde puede cambiar la voz y la edad utilizando el

synthesizer.SelectVoiceByHints(VoiceGender.Male , VoiceAge.Adult); 
Cuestiones relacionadas