SrgsToken.Pronunciation Propriété

Définition

Obtient ou définit la chaîne qui définit la prononciation du jeton.

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

Valeur de propriété

Retourne une chaîne contenant les téléphones de l'alphabet phonétique spécifié dans PhoneticAlphabet.

Exceptions

Une tentative est effectuée pour attribuer à Pronunciation la valeur null.

Tentative d'assignation d'une chaîne vide à Pronunciation.

Exemples

La grammaire de l’exemple suivant contient des mots d’argot et a également un mot rare : « whatchamacallit ». L’ajout d’une prononciation inline personnalisée à l’aide Pronunciation de la propriété de la SrgsToken classe peut améliorer la précision de la reconnaissance pour le mot « whatchamacallit » ainsi que pour l’ensemble de l’expression qui le contient. L’exemple utilise des téléphones de l’upS (Microsoft Universal Phone Set) pour définir les prononciations personnalisées.

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

Remarques

Les téléphones sont des lettres ou des symboles qui décrivent les sons de la parole. System.Speech prend en charge trois alphabets phonétiques pour spécifier des prononciations personnalisées : upS (Universal Phone Set), l’ensemble de téléphones SAPI (Speech API) et l’alphabet phonétique international (IPA). Les téléphones spécifiés dans Pronunciation doivent correspondre à l’alphabet phonétique spécifié dans PhoneticAlphabet. Pour plus d’informations , consultez Lexiques et alphabets phonétiques .

Les téléphones spécifiés dans Pronunciation indiquent comment le contenu de Text doit être prononcé pour une reconnaissance réussie. Le moteur de reconnaissance vocale utilise la prononciation spécifiée dans Pronunciation pour faire correspondre l’entrée vocale et retourne la chaîne contenue par Text dans le résultat de la reconnaissance.

Si les téléphones ne sont pas délimités par l’espace ou si la chaîne spécifiée contient un téléphone non reconnu, le moteur de reconnaissance ne reconnaît pas la prononciation spécifiée comme une prononciation valide du mot contenu par Text.

Les prononciations spécifiées dans Pronunciation sont prioritaires sur les prononciations spécifiées dans les lexiques associées à une grammaire ou à un moteur de reconnaissance. En outre, la prononciation dans la Pronunciation propriété s’applique uniquement à l’occurrence unique du mot ou de l’expression contenu par Text.

S’applique à

Voir aussi