本文整理汇总了C#中GrammarBuilder.AppendDictation方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarBuilder.AppendDictation方法的具体用法?C# GrammarBuilder.AppendDictation怎么用?C# GrammarBuilder.AppendDictation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrammarBuilder
的用法示例。
在下文中一共展示了GrammarBuilder.AppendDictation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetGrammar_Custom
public GrammarBuilder GetGrammar_Custom(string grammar)
{
Choices globalChoices = new Choices();
string[] sentences = grammar.Split('|');
foreach (string s in sentences)
{
GrammarBuilder sentenceBuilder = new GrammarBuilder();
string[] words = s.Split(' ');
foreach (string w in words)
{
if (m_vocabulories.ContainsKey(w))
sentenceBuilder.Append(new Choices(m_vocabulories[w].ToArray()));
else if (w == "#Dictation")
sentenceBuilder.AppendDictation();
else if (w == "#WildCard")
sentenceBuilder.AppendWildcard();
else if (w != "")
sentenceBuilder.Append(w);
}
globalChoices.Add(sentenceBuilder);
}
GrammarBuilder globalBuilder = new GrammarBuilder(globalChoices);
globalBuilder.Culture = m_culture;
Console.WriteLine(globalBuilder.DebugShowPhrases);
return globalBuilder;
}
示例2: appendDictation
public ChainedGrammar appendDictation(string key)
{
GrammarBuilder b = new GrammarBuilder();
b.AppendDictation();
builder.Append(new SemanticResultKey(key, b));
return this;
}
示例3: MakeGrammarBuilderRecursively
private static GrammarBuilder MakeGrammarBuilderRecursively(RadTreeNode currentNode)
{
GrammarBuilder currentGrammar = new GrammarBuilder();
if ((currentNode.Tag as GrammarTreeViewTag).Optional != true &&
(currentNode.Tag as GrammarTreeViewTag).IsDictation != true)
{
currentGrammar = new GrammarBuilder(new SemanticResultKey(currentNode.Text, new GrammarBuilder(currentNode.Text)));
}
else if ((currentNode.Tag as GrammarTreeViewTag).Optional && (currentNode.Tag as GrammarTreeViewTag).IsDictation != true)
{
currentGrammar = new GrammarBuilder(new SemanticResultKey(currentNode.Text, new GrammarBuilder(currentNode.Text)), 0, 1);
}
else if ((currentNode.Tag as GrammarTreeViewTag).IsDictation)
{
GrammarBuilder fakeDictation = new GrammarBuilder();
string dictation = (currentNode.Tag as GrammarTreeViewTag).DictationContext;
if (dictation == string.Empty)
{
fakeDictation.AppendDictation();
}
else
{
fakeDictation.AppendDictation(dictation);
}
if ((currentNode.Tag as GrammarTreeViewTag).Optional)
{
currentGrammar = new GrammarBuilder(new SemanticResultKey(currentNode.Text, fakeDictation), 0, 1);
}
else
{
currentGrammar = new GrammarBuilder(new SemanticResultKey(currentNode.Text, fakeDictation));
}
}
Choices tempGrammar = new Choices();
for (int i = 0; i < currentNode.Nodes.Count; i++)
{
tempGrammar.Add(MakeGrammarBuilderRecursively(currentNode.Nodes[i]));
}
if (tempGrammar.ToGrammarBuilder().DebugShowPhrases != "[]")
{
currentGrammar.Append(tempGrammar);
}
return currentGrammar;
}
示例4: InitializeRecognizers
private void InitializeRecognizers()
{
_recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
var gb = new GrammarBuilder {Culture = CultureInfo.GetCultureInfoByIetfLanguageTag("en")};
gb.AppendDictation();
_recognizer.LoadGrammar(new Grammar(gb)); // load a "hello computer" grammar
_recognizer.SpeechRecognized += _recognizeSpeechAndMakeSureTheComputerSpeaksToYou_SpeechRecognized;
// if speech is recognized, call the specified method
_recognizer.SetInputToDefaultAudioDevice();
}
示例5: SpeechRecognizerServer
public SpeechRecognizerServer(string moduleName)
{
System.Collections.ObjectModel.ReadOnlyCollection<RecognizerInfo> installedRecognizers = SpeechRecognitionEngine.InstalledRecognizers();
//Synchronous Recognition
m_reco = new System.Speech.Recognition.SpeechRecognitionEngine(myLanguage);
Network.init();
m_moduleName = moduleName;
//TTS
m_tts = new System.Speech.Synthesis.SpeechSynthesizer();
m_portISpeak = new Port();
m_portISpeak.open("/" + moduleName + "/tts/iSpeak:o");
Network.connect("/" + moduleName + "/tts/iSpeak:o", "/iSpeak");
//Grammars
GrammarBuilder dictation = new GrammarBuilder();
dictation.Culture = myLanguage;
dictation.AppendDictation();
m_grammar_dictation = new Grammar(dictation);
GrammarBuilder spelling = new GrammarBuilder();
spelling.Culture = myLanguage;
spelling.AppendDictation("spelling");
m_grammar_dictation_spelling = new Grammar(spelling);
m_grammar_continuous = new GrammarBuilder("For sure this non empty grammar will never be recognized.");
m_reco.SetInputToDefaultAudioDevice();
m_reco.LoadGrammar(m_grammar_dictation);
//Continuous Recognition
m_reco_continuous = new SpeechRecognitionEngine();
m_reco_continuous.SetInputToDefaultAudioDevice();
m_portContinuousRecognition = new Port();
m_portContinuousRecognition.open("/" + moduleName + "/recog/continuous:o");
m_reco_continuous.LoadGrammar(new Grammar(m_grammar_continuous));
m_reco_continuous.RecognizeCompleted += onContinuousRecognitionResult;
m_reco_continuous.RecognizeAsync();
m_grammarManager = new RobotGrammarManager();
m_grammarManager.InitialiseVocabulories();
SetLanguage("EN-us");
//SetLanguage("fr-fr");
Console.WriteLine("#########################");
Console.WriteLine("# Speech Recognizer #");
Console.WriteLine("#########################");
Network.init();
m_rpcPort = new Port();
m_rpcPort.open("/" + m_moduleName + "/rpc");
m_rpcThread = new System.Threading.Thread(HandleRPC);
m_rpcThread.Start();
}
示例6: Main
static void Main(string[] args)
{
// Select a speech recognizer that supports English.
RecognizerInfo info = null;
foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
if (ri.Culture.TwoLetterISOLanguageName.Equals("en"))
{
info = ri;
break;
}
}
if (info == null) return;
// Create the selected recognizer.
using (SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine(info))
{
var gb = new GrammarBuilder();
gb.AppendDictation();
var g = new Grammar(gb);
// Create and load a dictation grammar.
recognizer.LoadGrammar(g);
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous, continuous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
}
示例7: CreateSampleGrammar
private Grammar CreateSampleGrammar(Controller.MainController.Mapping mapping)
{
GrammarBuilder grammarBuilder = new GrammarBuilder(mapping.prefix);
if (mapping.useDictation)
{
grammarBuilder.AppendDictation();
}
else
{
Choices choices = new Choices();
foreach (string choice in mapping.list)
{
choices.Add(choice);
}
grammarBuilder.Append(choices);
}
Grammar g = new Grammar(grammarBuilder);
g.Name = "Commands";
return g;
}
示例8: Load_Answer_Grammar
public static SpeechRecognitionEngine Load_Answer_Grammar(SpeechRecognitionEngine oRecognizer, string propDatatype, string propObjectType)
{
#region [OBJECT]'s [PROPERTY]
//OBJECT's PROPERTY
List<string> noneList = new List<string>();
noneList.Add("None");
noneList.Add("Unknown");
noneList.Add("Ignore");
noneList.Add("Nevermind");
Choices noneChoices = new Choices(noneList.ToArray());
GrammarBuilder gb_Single = new GrammarBuilder();
GrammarBuilder dictation = new GrammarBuilder();
dictation.AppendDictation();
gb_Single.Append(new SemanticResultKey("ANSWER", dictation));
Grammar g_Single = new Grammar(gb_Single);
g_Single.Name = "ANSWER";
oRecognizer.LoadGrammar(g_Single);
#endregion
return oRecognizer;
}
示例9: Main
static void Main( string[] args )
{
try {
using ( var source = new KinectAudioSource() ) {
source.FeatureMode = true;
source.AutomaticGainControl = false; //Important to turn this off for speech recognition
source.SystemMode = SystemMode.OptibeamArrayOnly; //No AEC for this sample
RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where( r => "ja-JP".Equals( r.Culture.Name, StringComparison.InvariantCultureIgnoreCase ) ).FirstOrDefault();
if ( ri == null ) {
Console.WriteLine( "Could not find speech recognizer: {0}. Please refer to the sample requirements.", RecognizerId );
return;
}
Console.WriteLine( "Using: {0}", ri.Name );
using ( var sre = new SpeechRecognitionEngine( ri.Id ) ) {
GrammarBuilder dictaphoneGB = new GrammarBuilder();
GrammarBuilder dictation = new GrammarBuilder();
dictation.AppendDictation();
dictaphoneGB.Append( new SemanticResultKey( "StartDictation", new SemanticResultValue( "Start Dictation", true ) ) );
dictaphoneGB.Append( new SemanticResultKey( "dictationInput", dictation ) );
dictaphoneGB.Append( new SemanticResultKey( "EndDictation", new SemanticResultValue( "Stop Dictation", false ) ) );
GrammarBuilder spellingGB = new GrammarBuilder();
GrammarBuilder spelling = new GrammarBuilder();
spelling.AppendDictation( "spelling" );
spellingGB.Append( new SemanticResultKey( "StartSpelling", new SemanticResultValue( "Start Spelling", true ) ) );
spellingGB.Append( new SemanticResultKey( "spellingInput", spelling ) );
spellingGB.Append( new SemanticResultKey( "StopSpelling", new SemanticResultValue( "Stop Spelling", true ) ) );
GrammarBuilder both = GrammarBuilder.Add( (GrammarBuilder)new SemanticResultKey( "Dictation", dictaphoneGB ),
(GrammarBuilder)new SemanticResultKey( "Spelling", spellingGB ) );
Grammar grammar = new Grammar( new SemanticResultKey( "Dictation", dictaphoneGB ) );
grammar.Enabled = true;
grammar.Name = "Dictaphone and Spelling ";
sre.LoadGrammar( grammar ); // Exception thrown here
sre.SpeechRecognized += SreSpeechRecognized;
sre.SpeechHypothesized += SreSpeechHypothesized;
sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;
using ( Stream s = source.Start() ) {
sre.SetInputToAudioStream( s, new SpeechAudioFormatInfo(
EncodingFormat.Pcm, 16000, 16, 1,
32000, 2, null ) );
Console.WriteLine( "Recognizing. Say: 'red', 'green' or 'blue'. Press ENTER to stop" );
sre.RecognizeAsync( RecognizeMode.Multiple );
Console.ReadLine();
Console.WriteLine( "Stopping recognizer ..." );
sre.RecognizeAsyncStop();
}
}
}
}
catch ( Exception ex ) {
Console.WriteLine( ex.Message );
}
}
示例10: Load_Text_Only_Grammars
public static SpeechRecognitionEngine Load_Text_Only_Grammars(SpeechRecognitionEngine oRecognizer)
{
DataSet dsResults = new DataSet();
#region Build a List of all Objects AND Possessive Objects
List<string> objectFullList = new List<string>();
List<string> objectPossessiveList = new List<string>();
//Get All objects
dsResults = OSAESql.RunSQL("SELECT object_name, CONCAT(object_name,'''s') AS possessive_name FROM osae_v_object_list_full");
for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++)
{
string grammer = dsResults.Tables[0].Rows[i][0].ToString();
string possessivegrammer = dsResults.Tables[0].Rows[i][1].ToString();
if (!string.IsNullOrEmpty(grammer)) objectFullList.Add(grammer);
if (!string.IsNullOrEmpty(possessivegrammer)) objectPossessiveList.Add(possessivegrammer);
}
Choices objectFullChoices = new Choices(objectFullList.ToArray());
Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray());
#endregion
#region Build a List of all Object Types
List<string> objectTypeList = new List<string>();
dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type");
foreach (DataRow dr in dsResults.Tables[0].Rows)
{
objectTypeList.Add(dr[0].ToString());
}
Choices objectTypeChoices = new Choices(objectTypeList.ToArray());
#endregion
#region [OBJECT]'s [PROPERTY] is [VALUE]
//OBJECT's PROPERTY is [VALUE]
foreach (string ot in objectTypeList)
{
List<string> objectList = new List<string>();
GrammarBuilder gbObjectPropertyIs = new GrammarBuilder();
//Get All objects of the current Object Type
dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
foreach (DataRow dr in dsResults.Tables[0].Rows)
{
objectList.Add(dr[0].ToString());
}
if (objectList.Count > 0) // Only bother with this object type if there are objects using it
{
Choices objectChoices = new Choices(objectList.ToArray());
SemanticResultKey srk = new SemanticResultKey("PARAM1", objectChoices);
gbObjectPropertyIs.Append(srk);
//Now the the appropriate properties
DataSet dsPropType = OSAESql.RunSQL("SELECT DISTINCT(property_datatype),property_object_type FROM osae_v_object_type_property WHERE object_type='" + ot + "' ORDER BY property_datatype");
foreach (DataRow drType in dsPropType.Tables[0].Rows)
{
List<string> propertyList = new List<string>();
DataSet dsPropName = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='" + drType["property_datatype"].ToString() + "' ORDER BY property_datatype");
foreach (DataRow drName in dsPropName.Tables[0].Rows)
{
propertyList.Add(drName["property_name"].ToString());
}
Choices propertyChoices = new Choices(propertyList.ToArray());
if (drType["property_datatype"].ToString().ToUpper() == "STRING")
{
GrammarBuilder dictation = new GrammarBuilder();
dictation.AppendDictation();
srk = new SemanticResultKey("PARAM2", propertyChoices);
gbObjectPropertyIs.Append(srk);
gbObjectPropertyIs.Append("is");
gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", dictation));
Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
oRecognizer.LoadGrammar(gObjectPropertyIs);
}
else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT")
{
srk = new SemanticResultKey("PARAM2", propertyChoices);
gbObjectPropertyIs.Append(srk);
gbObjectPropertyIs.Append("is");
gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", objectFullChoices));
Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
oRecognizer.LoadGrammar(gObjectPropertyIs);
}
else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT TYPE")
{
List<string> propertyOTList = new List<string>();
DataSet dsPropObjectType = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + drType["property_object_type"].ToString() + "'");
foreach (DataRow drName in dsPropObjectType.Tables[0].Rows)
{
propertyOTList.Add(drName["object_name"].ToString());
}
Choices propertyOTChoices = new Choices(propertyOTList.ToArray());
srk = new SemanticResultKey("PARAM2", propertyChoices);
gbObjectPropertyIs.Append(srk);
gbObjectPropertyIs.Append("is");
gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", propertyOTChoices));
Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
//.........这里部分代码省略.........
示例11: ToGrammarBuilder
public GrammarBuilder ToGrammarBuilder()
{
GrammarBuilder builder = new GrammarBuilder();
Queue<PhoneticChoice> foundChoices;
String[] tokens = ToTokens(out foundChoices);
foreach (String token in tokens)
{
switch (token)
{
case CHOICE:
PhoneticChoice choice = foundChoices.Dequeue();
builder.Append(new Choices(choice.PossibleValues));
break;
case WILD_CARD:
builder.AppendWildcard();
break;
case DICTATION:
builder.AppendDictation();
break;
default:
//Regular Text is just appended
builder.Append(token);
break;
}
}
return builder;
}
示例12: SetLanguage
public bool SetLanguage(string cultureName)
{
//System.Globalization.CultureInfo[] cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures);
System.Globalization.CultureInfo culture;
try
{
culture = System.Globalization.CultureInfo.GetCultureInfoByIetfLanguageTag(cultureName);
}
catch
{
Console.WriteLine("Culture info is not found.");
return false;
}
myLanguage = culture;
System.Collections.ObjectModel.ReadOnlyCollection<InstalledVoice> voices = m_tts.GetInstalledVoices(culture);
if (voices.Count > 0)
m_tts.SelectVoice(voices.First().VoiceInfo.Name);
m_reco = new System.Speech.Recognition.SpeechRecognitionEngine(culture);
m_reco.SetInputToDefaultAudioDevice();
GrammarBuilder dictation = new GrammarBuilder();
dictation.Culture = myLanguage;
dictation.AppendDictation();
m_grammar_dictation = new Grammar(dictation);
m_reco.LoadGrammar(m_grammar_dictation);
m_reco_continuous.RecognizeCompleted -= onContinuousRecognitionResult;
m_reco_continuous.RecognizeAsyncCancel();
//m_reco_continuous.RecognizeAsyncStop();
m_reco_continuous = new SpeechRecognitionEngine(culture);
m_reco_continuous.SetInputToDefaultAudioDevice();
m_grammar_continuous.Culture = culture;
m_reco_continuous.LoadGrammar(new Grammar(m_grammar_continuous));
m_reco_continuous.RecognizeCompleted += onContinuousRecognitionResult;
m_reco_continuous.RecognizeAsync();
m_grammarManager.SetLanguage(cultureName);
Console.WriteLine("The culture has been set to " + cultureName);
return true;
}
示例13: Load_Voice_Grammars
//.........这里部分代码省略.........
g4.Name = "Is [OBJECT] [STATE]";
oRecognizer.LoadGrammar(g4);
gb5.Append(srk);
Grammar g5 = new Grammar(gb5);
g5.Name = "[OBJECT] is [STATE]";
oRecognizer.LoadGrammar(g5);
gb6.Append(srk);
Grammar g6 = new Grammar(gb6);
g6.Name = "[OBJECT] is [STATE]";
oRecognizer.LoadGrammar(g6);
gb7.Append(srk);
Grammar g7 = new Grammar(gb7);
g7.Name = "[OBJECT] is [STATE]";
oRecognizer.LoadGrammar(g7);
#endregion
#region [Object] [Method] [Parameter]
// 1 OBJECT STATE {PARAMETER}
srk = new SemanticResultKey("PARAM1", objectFullChoices);
gb1 = new GrammarBuilder(srk);
//Now the the appropriate method
List<string> methodList = new List<string>();
dsResults = OSAESql.RunSQL("SELECT DISTINCT method_label FROM osae_v_object_type_method_list_full");
foreach (DataRow dr in dsResults.Tables[0].Rows)
methodList.Add(dr[0].ToString());
Choices methodChoices = new Choices(methodList.ToArray());
srk = new SemanticResultKey("PARAM2", methodChoices);
gb1.Append(srk);
gb1.AppendDictation();
g1 = new Grammar(gb7);
g1.Name = "[OBJECT] [METHOD] [PARAMETER]";
oRecognizer.LoadGrammar(g1);
#endregion
#region [OBJECT] [CONTAINER]
// 1 OBJECT is in CONTAINER
// 2 np OBJECT is in CONTAINER
// 3 OBJECT is in np CONTAINER
// 4 np OBJECT is in np CONTAINER
// 5 I am/You are in CONTAINER
// 6 I am/You are in np CONTAINER
// 7 is OBJECT in CONTAINER
// 8 is np OBJECT in CONTAINER
// 9 is OBJECT in np CONTAINER
// 10 is np OBJECT in np CONTAINER
// 11 am I/are you in CONTAINER
// 12 am I/are you in NP CONTAINER
// 1 OBJECT is in CONTAINER
GrammarBuilder gb_GrammarBuilder = new GrammarBuilder();
srk = new SemanticResultKey("PARAM1", objectFullChoices);
gb_GrammarBuilder.Append(srk);
gb_GrammarBuilder.Append("is in");
srk = new SemanticResultKey("PARAM2", containerChoices);
gb_GrammarBuilder.Append(srk);
Grammar g_Grammar = new Grammar(gb_GrammarBuilder);
g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
oRecognizer.LoadGrammar(g_Grammar);
示例14: Load_OSA_Grammar
//.........这里部分代码省略.........
foreach (string ot in objectTypeList)
{
List<string> objectList = new List<string>();
GrammarBuilder gbObjectPropertyIs = new GrammarBuilder();
//Get All objects of the current Object Type
dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
foreach (DataRow dr in dsResults.Tables[0].Rows)
{
objectList.Add(dr[0].ToString());
}
if (objectList.Count > 0) // Only bother with this object type if there are objects using it
{
Choices objectChoices = new Choices(objectList.ToArray());
srk = new SemanticResultKey("PARAM1", objectChoices);
gbObjectPropertyIs.Append(srk);
//Now the the appropriate properties
DataSet dsPropType = OSAESql.RunSQL("SELECT DISTINCT(property_datatype),property_object_type FROM osae_v_object_type_property WHERE object_type='" + ot + "' ORDER BY property_datatype");
foreach (DataRow drType in dsPropType.Tables[0].Rows)
{
List<string> propertyList = new List<string>();
DataSet dsPropName = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='" + drType["property_datatype"].ToString() + "' ORDER BY property_datatype");
foreach (DataRow drName in dsPropName.Tables[0].Rows)
{
propertyList.Add(drName["property_name"].ToString());
}
Choices propertyChoices = new Choices(propertyList.ToArray());
if (drType["property_datatype"].ToString().ToUpper() == "STRING")
{
GrammarBuilder dictation = new GrammarBuilder();
dictation.AppendDictation();
srk = new SemanticResultKey("PARAM2", propertyChoices);
gbObjectPropertyIs.Append(srk);
gbObjectPropertyIs.Append("is");
gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", dictation));
Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
oRecognizer.LoadGrammar(gObjectPropertyIs);
}
else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT")
{
srk = new SemanticResultKey("PARAM2", propertyChoices);
gbObjectPropertyIs.Append(srk);
gbObjectPropertyIs.Append("is");
gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", objectFullChoices));
Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
oRecognizer.LoadGrammar(gObjectPropertyIs);
}
else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT TYPE")
{
List<string> propertyOTList = new List<string>();
DataSet dsPropObjectType = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + drType["property_object_type"].ToString() + "'");
foreach (DataRow drName in dsPropObjectType.Tables[0].Rows)
{
propertyOTList.Add(drName["object_name"].ToString());
}
Choices propertyOTChoices = new Choices(propertyOTList.ToArray());
srk = new SemanticResultKey("PARAM2", propertyChoices);
gbObjectPropertyIs.Append(srk);
gbObjectPropertyIs.Append("is");
示例15: CreateGrammars
/// <summary>
/// Creates Grammar objects based on the spoken commands to listen for and loads
/// them into the speech recognition engine.
/// </summary>
private void CreateGrammars()
{
Choices choices = new Choices();
choices.Add(new[] { syncCommand });
Choices wildcardChoices = new Choices();
bool wildcardChoiceAdded = false;
foreach (string phrase in AudioCallbacks.Keys) {
string command = phrase;
if (command.EndsWith("*")) {
command = command.TrimEnd('*');
GrammarBuilder builder = new GrammarBuilder(command);
builder.AppendDictation();
wildcardChoices.Add(builder);
wildcardChoiceAdded = true;
}
else {
choices.Add(command);
}
}
GrammarBuilder commandsBuilder = new GrammarBuilder(choices);
Grammar grammar = new Grammar(commandsBuilder);
grammar.Enabled = true;
grammar.Name = syncCommand;
speechEngine.LoadGrammar(grammar);
// An exception is thrown if no items exist in the builder so only create a Grammar
// if at least one wildcard statement exists
if (wildcardChoiceAdded) {
GrammarBuilder wildcardCommandsBuilder = new GrammarBuilder(wildcardChoices);
Grammar wildcardGrammar = new Grammar(wildcardCommandsBuilder);
wildcardGrammar.Enabled = true;
wildcardGrammar.Name = syncCommand + " - Wildcards";
speechEngine.LoadGrammar(wildcardGrammar);
}
}