SrgsToken.Pronunciation Propiedad

Definición

Obtiene o establece la cadena que define la pronunciación para el token.

public:
 property System::String ^ Pronunciation { System::String ^ get(); void set(System::String ^ value); };
public string Pronunciation { get; set; }
member this.Pronunciation : string with get, set
Public Property Pronunciation As String

Valor de propiedad

Devuelve una cadena que contiene teléfonos del alfabeto fonético especificado en PhoneticAlphabet.

Excepciones

Se ha intentado establecer Pronunciation en null.

Se intentó asignar una cadena vacía a Pronunciation.

Ejemplos

La gramática del ejemplo siguiente contiene palabras jergas y también tiene una palabra poco común: "whatchamacallit". Agregar una pronunciación insertada personalizada mediante la Pronunciation propiedad de la SrgsToken clase puede mejorar la precisión del reconocimiento de la palabra "whatchamacallit", así como para toda la frase que lo contiene. En el ejemplo se usan teléfonos del Conjunto de teléfonos universales de Microsoft (UPS) para definir las pronunciaciones personalizadas.

using System;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;

namespace SampleRecognition
{
  class Program
  {
    static void Main(string[] args)

    // Initialize an instance of the in-process recognizer.
    {
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
      {

        // Build the SrgsOneOf objects with alternative choices for the slang phrase.
        SrgsOneOf gimme = new SrgsOneOf(
          new string[] { "give me", "gimme", "hand me", "ha'me" });
        SrgsOneOf the = new SrgsOneOf(new string[] { "the", "duh" });

        // Build the one-of element that contains the pronunciation.
        SrgsItem thing = new SrgsItem("thingamajig");
        SrgsItem whatcha = new SrgsItem();
        SrgsToken callit = new SrgsToken("whatchamacallit");
        callit.Pronunciation = "W AE T CH AE M AE K AA L IH T";
        whatcha.Add(callit);
        SrgsOneOf what = new SrgsOneOf(new SrgsItem[] {thing, whatcha});

        // Create the rule from the SrgsOneOf objects.
        SrgsRule slangRule = new SrgsRule("slang", gimme, the, what);

        // Build an SrgsDocument object from the rule and set the phonetic alphabet.
        SrgsDocument tokenPron = new SrgsDocument(slangRule);
        tokenPron.PhoneticAlphabet = SrgsPhoneticAlphabet.Ups;

        // Create a Grammar object from the SrgsDocument and load it to the recognizer.
        Grammar g_Slang = new Grammar(tokenPron);
        g_Slang.Name = ("Slang Pronunciation");
        recognizer.LoadGrammarAsync(g_Slang);

        // Configure recognizer input.
        recognizer.SetInputToDefaultAudioDevice();

        // Attach a handler for the SpeechRecognized event.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

        // Start asynchronous recognition.
        recognizer.RecognizeAsync();
        Console.WriteLine("Starting asynchronous recognition...");

        // Keep the console window open.
        Console.ReadLine();
      }
    }

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine("Recognized phrase: " + e.Result.Text);
      Console.WriteLine("Confidence: " + e.Result.Confidence);
      Console.WriteLine("  Word summary: ");
      foreach (RecognizedWordUnit word in e.Result.Words)
      {
        Console.WriteLine(
          "    Lexical form ({1})" +
          " Pronunciation ({0})" +
          " Confidence ({2})",
          word.Pronunciation, word.LexicalForm, word.Confidence);
      }
    }
  }
}

Comentarios

Los teléfonos son letras o símbolos que describen los sonidos de voz. System.Speech admite tres alfabetos fonéticos para especificar pronunciaciones personalizadas: el conjunto de teléfonos universales (UPS), el conjunto de teléfonos de Speech API (SAPI) y el alfabeto fonético internacional (IPA). Los teléfonos especificados en Pronunciation deben coincidir con el alfabeto fonético especificado en PhoneticAlphabet. Consulte Léxico y alfabetos fonéticos para obtener más información.

Los teléfonos especificados en Pronunciation indican cómo se debe pronunciar el contenido de Text para el reconocimiento correcto. El motor de reconocimiento de voz usa la pronunciación especificada en Pronunciation para hacer coincidir la entrada de voz y devuelve la cadena contenida Text en el resultado del reconocimiento.

Si los teléfonos no están delimitados por espacios o la cadena especificada contiene un teléfono no reconocido, el motor de reconocimiento no reconoce la pronunciación especificada como una pronunciación válida de la palabra contenida en Text.

Las pronunciaciones especificadas en Pronunciation tienen prioridad sobre las pronunciaciones especificadas en léxico asociados a una gramática o a un motor de reconocimiento. Además, la pronunciación de la Pronunciation propiedad solo se aplica a la única aparición de la palabra o frase contenida en Text.

Se aplica a

Consulte también