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拼音字母表匹配。 有关详细信息 ,请参阅词典和拼音字母 表。

中指定的 Pronunciation 手机指示应如何 Text 发音才能成功识别。 语音识别引擎使用 中指定的 Pronunciation 发音来匹配语音输入,并返回识别结果中包含的 字符串 Text

如果电话没有空格分隔或指定的字符串包含无法识别的电话,则识别引擎不会将指定的发音识别为 包含 Text的单词的有效发音。

中指定的 Pronunciation 发音优先于与语法或识别引擎关联的词典中指定的发音。 此外, 属性中的 Pronunciation 发音仅适用于 包含 Text的单词或短语的单个匹配项。

适用于

另请参阅