SrgsToken.Pronunciation Vlastnost

Definice

Získá nebo nastaví řetězec, který definuje výslovnost pro 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

Hodnota vlastnosti

Vrátí řetězec obsahující telefony z fonetické abecedy zadané v PhoneticAlphabet.

Výjimky

Došlo k pokusu o nastavení Pronunciation na nullhodnotu .

Dojde k pokusu o přiřazení prázdného řetězce k Pronunciation.

Příklady

Gramatika v následujícím příkladu obsahuje slangová slova a má také neobvyklé slovo: "whatchamacallit". Přidání vlastní vložené výslovnosti pomocí Pronunciation vlastnosti SrgsToken třídy může zlepšit přesnost rozpoznávání slova "whatchamacallit" i pro celou frázi, která ho obsahuje. V tomto příkladu se k definování vlastní výslovnosti používají telefony ze sady Microsoft Universal Phone Set (UPS).

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

Poznámky

Telefony jsou písmena nebo symboly, které popisují zvuky řeči. System.Speech podporuje tři fonetické abecedy pro určení vlastní výslovnosti: sadu UPS (Universal Phone Set), sadu pro telefony rozhraní Speech API (SAPI) a mezinárodní fonetickou abecedu (IPA). Telefony zadané v Pronunciation musí odpovídat fonetické abecedě zadané v PhoneticAlphabet. Další informace najdete v tématu Lexikony a fonetické abecedy .

Telefony zadané v Pronunciation indikují, jak by měl být obsah Text vyslovován pro úspěšné rozpoznání. Modul rozpoznávání řeči používá výslovnost zadanou v Pronunciation ke shodě vstupu řeči a vrátí řetězec obsažený Text ve výsledku rozpoznávání.

Pokud telefony nejsou oddělené mezerami nebo zadaný řetězec obsahuje nerozpoznaný telefon, modul rozpoznávání nerozpozná zadanou výslovnost jako platnou výslovnost slova obsaženého v Text.

Výslovnost zadaná v Pronunciation mají přednost před výslovností zadanou v lexikonech přidružených k gramatickému nebo rozpoznávacímu modulu. Výslovnost ve Pronunciation vlastnosti se také vztahuje pouze na jeden výskyt slova nebo fráze obsažené v Text.

Platí pro

Viz také