共用方式為


SrgsToken.Pronunciation 屬性

定義

取得或設定用來定義語彙基元發音的字串。

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

屬性值

傳回字串,包含來自 PhoneticAlphabet 中所指定語音字母的音素。

例外狀況

嘗試將 Pronunciation 設定為 null

嘗試要將空字串指派給 Pronunciation

範例

下列範例中的文法包含語言字組,也有不常見的字組:「whatchamacallit」。 使用 Pronunciation 類別的 SrgsToken 屬性新增自訂的內嵌發音,可以改善 「whatchamacallit」 字組的辨識精確度,以及包含該字的整個片語。 此範例會使用來自 Microsoft 通用電話組的手機 (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);
      }
    }
  }
}

備註

手機是描述語音音效的字母或符號。 System.Speech 支援三個語音字母來指定自訂發音:通用電話集 (UPS) 、語音 API (SAPI) 電話集,以及國際語音字母 (IPA) 。 中指定的 Pronunciation 手機必須符合 中指定的 PhoneticAlphabet 注音字母。 如需詳細資訊,請參閱 Lexicons 和注音字母

中指定的 Pronunciation 手機會指出 的內容應該如何 Text 發音,以便成功辨識。 語音辨識引擎會使用 中指定的 Pronunciation 發音來比對語音輸入,並傳回辨識結果中包含的字串 Text

如果手機不是以空格分隔,或指定的字串包含無法辨識的手機,辨識引擎就不會將指定的發音辨識為 包含 Text 之文字的有效發音。

中指定的 Pronunciation 發音優先于與文法或辨識引擎相關聯的語彙中所指定的發音。 此外,屬性中的 Pronunciation 發音只適用于 所 Text 包含單一出現的單字或片語。

適用於

另請參閱