SrgsToken.Pronunciation Proprietà

Definizione

Ottiene o imposta la stringa che definisce la pronuncia per il 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

Valore della proprietà

Restituisce una stringa contenente i telefoni dall'alfabeto fonetico specificato in PhoneticAlphabet.

Eccezioni

Si è tentato di impostare Pronunciation su null.

Viene effettuato un tentativo di assegnazione di una stringa vuota a Pronunciation.

Esempio

La grammatica nell'esempio seguente contiene parole gergo e ha anche una parola non comune: "whatchamacallit". L'aggiunta di una pronuncia inline personalizzata usando la Pronunciation proprietà della SrgsToken classe può migliorare l'accuratezza del riconoscimento per la parola "whatchamacallit" e per l'intera frase che lo contiene. L'esempio usa telefoni del set di telefoni universali Microsoft per definire le pronunce personalizzate.

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

Commenti

I telefoni sono lettere o simboli che descrivono i suoni del parlato. System.Speech supporta tre alfabeti fonetici per specificare pronunce personalizzate: il set di telefoni universali (UPS), il set di telefoni DELL'API Voce (SAPI) e l'IPA (International Phonetic Alphabet). I telefoni specificati in Pronunciation devono corrispondere all'alfabeto fonetico specificato in PhoneticAlphabet. Per altre informazioni, vedere Lessico e Alfabeti fonetici .

I telefoni specificati in Pronunciation indicano come deve essere pronunciato il contenuto di Text per il riconoscimento riuscito. Il motore di riconoscimento vocale usa la pronuncia specificata in Pronunciation per trovare la corrispondenza con l'input vocale e restituisce la stringa contenuta Text nel risultato del riconoscimento.

Se i telefoni non sono delimitati da spazi o la stringa specificata contiene un telefono non riconosciuto, il motore di riconoscimento non riconosce la pronuncia specificata come pronuncia valida della parola contenuta da Text.

Le pronunce specificate in Pronunciation hanno la precedenza sulle pronunce specificate nei lessici associati a una grammatica o a un motore di riconoscimento. Inoltre, la pronuncia nella Pronunciation proprietà si applica solo alla singola occorrenza della parola o della frase contenuta in Text.

Si applica a

Vedi anche