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 で指定された発音記号から音素を含む文字列を返します。

例外

Pronunciationnull に設定しようとしました。

空の文字列を Pronunciation に割り当てようとしました。

次の例の文法にはスラング語が含まれており、"whatchamacallit" という一般的でない単語もあります。 クラスの プロパティを使用してカスタムのSrgsTokenインライン発音をPronunciation追加すると、"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)、Speech API (SAPI) 電話セット、国際音声アルファベット (IPA) の 3 つのふりがながサポートされています。 で指定する電話は、 でPronunciationPhoneticAlphabet指定されたふりがなと一致している必要があります。 詳細については、「 辞書とふりがな 」を参照してください。

Pronunciation 指定された電話は、認識を成功させるために の Text 内容を発音する方法を示します。 音声認識エンジンは、 で Pronunciation 指定された発音を使用して音声入力と一致し、認識結果に 含まれる Text 文字列を返します。

電話がスペース区切りでない場合、または指定した文字列に認識されない電話が含まれている場合、認識エンジンは指定された発音を に Text含まれる単語の有効な発音として認識しません。

Pronunciation 指定された発音は、文法または認識エンジンに関連付けられている辞書で指定された発音よりも優先されます。 また、 プロパティの発音は Pronunciation 、 に含まれる Text単語または語句の 1 回の出現にのみ適用されます。

適用対象

こちらもご覧ください