SemanticResultKey コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
SemanticResultKeyのインスタンスを構築し、キーを文法コンポーネントに関連付けます。
オーバーロード
| 名前 | 説明 |
|---|---|
| SemanticResultKey(String, GrammarBuilder[]) |
音声認識文法の作成に使用する 1 つ以上の GrammarBuilder オブジェクトにセマンティック キーを割り当てます。 |
| SemanticResultKey(String, String[]) |
音声認識文法の作成に使用する 1 つ以上の String インスタンスにセマンティック キーを割り当てます。 |
注釈
SemanticResultKeyのコンストラクターは、音声認識文法に追加するテキスト タグ (セマンティック キー) と文法コンポーネントのセットを指定します。
文法コンポーネントは、 GrammarBuilder オブジェクトの配列として、または String インスタンスの配列として指定できます。
文法コンポーネントが認識で使用されている場合は、セマンティック キーとしてSemanticResultKeyのコンストラクターに提供されるテキスト タグを使用して、返されたSemanticValueにアクセスできます。 SemanticValue インスタンスのValueプロパティは、SemanticResultKeyの定義で使用される文法コンポーネントによって決定されます。
SemanticResultKey(String, GrammarBuilder[])
音声認識文法の作成に使用する 1 つ以上の GrammarBuilder オブジェクトにセマンティック キーを割り当てます。
public:
SemanticResultKey(System::String ^ semanticResultKey, ... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ builders);
public SemanticResultKey(string semanticResultKey, params System.Speech.Recognition.GrammarBuilder[] builders);
new System.Speech.Recognition.SemanticResultKey : string * System.Speech.Recognition.GrammarBuilder[] -> System.Speech.Recognition.SemanticResultKey
Public Sub New (semanticResultKey As String, ParamArray builders As GrammarBuilder())
パラメーター
- semanticResultKey
- String
builders引数で指定されたGrammarBuilder オブジェクトに関連付けられたSemanticValue インスタンスにアクセスするためのセマンティック キーとして使用されるタグ。
- builders
- GrammarBuilder[]
semanticResultKeyで定義されたタグを使用してアクセスできるSemanticValue オブジェクトに関連付けられる文法コンポーネントの配列。
例
次の例では、"My password is ..." という形式のパスワード入力を認識する Grammar を作成します。ここで、実際の入力はワイルドカードと一致します。
ワイルドカードは、キー値が "Password" である SpeechRecognizer によってタグ付けされます。 SpeechRecognized ハンドラーは、このタグの有無を確認し、パスワードのオーディオ入力を取得して、パスワードを検証します。
private void pwdGrammar()
{
GrammarBuilder pwdBuilder = new GrammarBuilder("My Password is");
GrammarBuilder wildcardBuilder = new GrammarBuilder();
wildcardBuilder.AppendWildcard();
SemanticResultKey wildcardKey= new SemanticResultKey("Password", wildcardBuilder);
pwdBuilder+=wildcardKey;
Grammar grammar = new Grammar(pwdBuilder);
grammar.Name = "Password input";
grammar.SpeechRecognized +=
delegate(object sender, SpeechRecognizedEventArgs eventArgs)
{
SemanticValue semantics = eventArgs.Result.Semantics;
RecognitionResult result=eventArgs.Result;
if (!semantics.ContainsKey("Password"))
{
SpeechUI.SendTextFeedback(eventArgs.Result, "No Password Provided", false);
}
else
{
RecognizedAudio pwdAudio = result.GetAudioForWordRange(
result.Words[3],
result.Words[result.Words.Count - 1]);
MemoryStream pwdMemoryStream = new MemoryStream();
pwdAudio.WriteToAudioStream(pwdMemoryStream);
if (!IsValidPwd(pwdMemoryStream))
{
string badPwd = System.IO.Path.GetTempPath() + "BadPwd" + (new Random()).Next().ToString() + ".wav";
FileStream waveStream = new FileStream(badPwd, FileMode.Create);
pwdAudio.WriteToWaveStream(waveStream);
waveStream.Flush();
waveStream.Close();
SpeechUI.SendTextFeedback(eventArgs.Result, "Invalid Password", false);
}
}
};
grammar.Enabled = true;
_recognizer.LoadGrammar(grammar);
UpdateGrammarTree(_grammarTreeView, _recognizer);
}
注釈
暗黙的な変換のため、 builders 引数は、 SemanticResultValue、 SemanticResultKey、 Choices、および String オブジェクトもサポートします。 暗黙的な変換の詳細については、 Implicitを参照してください。
認識操作を実行すると、builders引数に指定されたGrammarBuilder オブジェクトが順次として扱われます。 たとえば、次の SemanticResultValue を使用して Grammarを構築する場合、認識エンジンへの入力には、認識する順序で "速い茶色のキツネ" という単語が含まれている必要があります。
SemanticResultKey stringTest=new SemanticResultKey(
"stringTest", new GrammarBuilder[] {
new GrammarBuilder("the"),
new GrammarBuilder("quick"),
new GrammarBuilder("brown"),
new GrammarBuilder("fox")});
semanticResultKey引数には、返される可能性があるSemanticValueにアクセスするために使用されるタグが含まれています。
SemanticValueのValueは、builders パラメーターによって提供されるGrammarBuilder インスタンスによって決まります。
GrammarBuilder オブジェクトにSemanticResultValueの定義インスタンスが含まれている場合、SemanticValueの値はnull。
builders パラメーターで指定されたGrammarBuilderオブジェクトが、認識ロジックによって使用されるタグなし (SemanticResultKey オブジェクトに関連付けられていない) SemanticResultValueインスタンスを提供する場合、SemanticResultValueのそのインスタンスは、生成されるSemanticValueのValueプロパティを定義します。
builders パラメーターで指定されたGrammarBuilder オブジェクトには、タグなし SemanticResultValue インスタンスが 1 つだけ存在する必要があります。 タグなし SemanticResultValue の複数のインスタンスが SemanticResultKeyに関連付けられている場合、それぞれが認識結果で生成された SemanticValue の値の設定を試みます。 これは許可されず、そのようなSemanticResultKey インスタンスを使用して作成されたGrammarを使用しようとすると、認識エンジンによって例外が生成されます。
builders パラメーターで指定され、既に別のSemanticResultKeyに関連付けられているGrammarBuilder オブジェクトに含まれるSemanticResultValueのインスタンスは、現在のSemanticResultKey インスタンスには影響しません。
適用対象
SemanticResultKey(String, String[])
音声認識文法の作成に使用する 1 つ以上の String インスタンスにセマンティック キーを割り当てます。
public:
SemanticResultKey(System::String ^ semanticResultKey, ... cli::array <System::String ^> ^ phrases);
public SemanticResultKey(string semanticResultKey, params string[] phrases);
new System.Speech.Recognition.SemanticResultKey : string * string[] -> System.Speech.Recognition.SemanticResultKey
Public Sub New (semanticResultKey As String, ParamArray phrases As String())
パラメーター
- semanticResultKey
- String
使用するタグは、phrases引数で指定されたString オブジェクトに関連付けられたSemanticValue インスタンスにアクセスします。
- phrases
- String[]
連結されたテキストが、semanticResultKeyで定義されたタグでアクセス可能なSemanticValue オブジェクトに関連付けられる 1 つ以上のString オブジェクト。
例
次の例では、SemanticResultKeyを使用するGrammarBuilder オブジェクトからGrammarを作成します。これは、String オブジェクトの配列によって定義されます。
作成された Grammar を使用する認識エンジンは、"赤い緑の青いゼロの色" という語句を認識します。 認識によって返されるRecognizedPhraseのセマンティクスには、"赤い緑の青" のValueを持つSemanticValueが含まれます。 "code" タグを使用して SemanticValue にアクセスできます。
GrammarBuilderに追加されるSemanticResultValue("zero", 5)のため、RecognizedPhraseのルート SemanticValue オブジェクトの値は 5 になります。
private void keyTest()
{
// Say "color red green blue zero"
GrammarBuilder gb = new GrammarBuilder("color") +
new SemanticResultKey("code",
(new string[] {"red", "green", "blue"})) +
new SemanticResultValue("zero", 5);
Grammar g = new Grammar(gb);
g.Name = "keyTest";
_recognizer.LoadGrammar(g);
}
注釈
認識操作を実行すると、phrases パラメーターで使用されるString オブジェクトはシーケンシャルとして扱われます。 たとえば、次の SemanticResultValue を使用して Grammarを構築する場合、認識エンジンへの入力には、認識する順序で "速い茶色のキツネ" という単語が含まれている必要があります。
SemanticResultKey stringTest=new SemanticResultKey("stringTest",
new string[] {
"the",
"quick",
"brown",
"fox"});
semanticResultKey引数は、返される可能性があるSemanticValueにアクセスするために使用されるキーを決定します。
文字列オブジェクトの配列を持つセマンティック キーを含むGrammarBuilder オブジェクトを使用してGrammarを構築する場合、認識操作によって生成されるSemanticValueのValueは、認識で使用される文字列になります。 前の例では、これは Value が "速い茶色のキツネ" であることを意味します。