本文整理汇总了C#中Choices类的典型用法代码示例。如果您正苦于以下问题:C# Choices类的具体用法?C# Choices怎么用?C# Choices使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Choices类属于命名空间,在下文中一共展示了Choices类的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: BuildGrammar
public Grammar BuildGrammar()
{
Choices choiceBuilder = new Choices();
// Songs
if (SongHelper.SongCount() > 0) // it freaks out if there's nothing in the one-of bit.
{
GrammarBuilder songBuilder = new GrammarBuilder();
songBuilder.Append("play song");
songBuilder.Append(SongHelper.GenerateSongChoices());
choiceBuilder.Add(songBuilder);
}
GrammarBuilder shuffleBuilder = new GrammarBuilder();
shuffleBuilder.Append("shuffle all songs");
choiceBuilder.Add(shuffleBuilder);
// Playlists
if (SongHelper.PlaylistCount() > 0)
{
GrammarBuilder playListBuilder = new GrammarBuilder();
playListBuilder.Append("play playlist");
playListBuilder.Append(SongHelper.GeneratePlaylistChoices());
choiceBuilder.Add(playListBuilder);
GrammarBuilder shufflePlayListBuilder = new GrammarBuilder();
shufflePlayListBuilder.Append("shuffle playlist");
shufflePlayListBuilder.Append(SongHelper.GeneratePlaylistChoices());
choiceBuilder.Add(shufflePlayListBuilder);
}
Grammar gram = new Grammar(new GrammarBuilder(choiceBuilder));
return gram;
}
示例3: Main
public Main()
{
InitializeComponent();
fontList.SelectedIndex = 0;
squareCenter = squareButton.Checked;
speechEngine.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(speechEngine_SpeechRecognized);
speechEngine.SetInputToDefaultAudioDevice();
Choices choices = new Choices("primes", "squares", "dots", "numbers");
foreach(string item in fontList.Items)
choices.Add("set font " + item);
for (int i = 0; i <= 999; ++i)
choices.Add("set size " + i);
GrammarBuilder grammarBuilder = new GrammarBuilder(choices);
speechEngine.LoadGrammar(new Grammar(grammarBuilder));
speechEngine.RecognizeAsync(RecognizeMode.Multiple);
init();
}
示例4: btnRecognize_Click
private void btnRecognize_Click(object sender, RoutedEventArgs e)
{
text = txtInput.Text.ToLower();
text = CleanText(text);
words = text.Split(' ');
wcount = words.Length;
//words = words.Distinct().ToArray();
txtOutput.Text = text;
Choices choices = new Choices(words);
GrammarBuilder gb = new GrammarBuilder(new GrammarBuilder(choices), 0, wcount);
//GrammarBuilder gb = new GrammarBuilder(txtInput.Text.Trim());
gb.Culture = new CultureInfo("es-MX");
Grammar grammar = new Grammar(gb);
//recognizer = new SpeechRecognitionEngine("SR_MS_es-MX_TELE_11.0");
//recognizer = new SpeechRecognitionEngine(new CultureInfo("es-MX"));
recognizer.LoadGrammar(grammar);
recognizer.SetInputToWaveFile(@"E:\Proyectos\Audio Timestamps\chapter01.wav");
//recognizer.SetInputToDefaultAudioDevice();
recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(RecognizeCompletedHandler);
recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
示例5: BuildSpeechEngine
void BuildSpeechEngine(RecognizerInfo rec)
{
_speechEngine = new SpeechRecognitionEngine(rec.Id);
var choices = new Choices();
choices.Add("venus");
choices.Add("mars");
choices.Add("earth");
choices.Add("jupiter");
choices.Add("sun");
var gb = new GrammarBuilder { Culture = rec.Culture };
gb.Append(choices);
var g = new Grammar(gb);
_speechEngine.LoadGrammar(g);
//recognized a word or words that may be a component of multiple complete phrases in a grammar.
_speechEngine.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(SpeechEngineSpeechHypothesized);
//receives input that matches any of its loaded and enabled Grammar objects.
_speechEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_speechEngineSpeechRecognized);
//receives input that does not match any of its loaded and enabled Grammar objects.
_speechEngine.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(_speechEngineSpeechRecognitionRejected);
//C# threads are MTA by default and calling RecognizeAsync in the same thread will cause an COM exception.
var t = new Thread(StartAudioStream);
t.Start();
}
示例6: BrightnessGrammar
private Grammar BrightnessGrammar()
{
// Change/Set Brightness to Choices
var choices = new Choices();
for (var i = -255; i <= 255; i++)
{
SemanticResultValue choiceResultValue = new SemanticResultValue(i.ToString(), i);
GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue);
choices.Add(resultValueBuilder);
}
GrammarBuilder changeGrammar = "Change";
GrammarBuilder setGrammar = "Set";
GrammarBuilder brightnessGrammar = "Brightness";
GrammarBuilder toGrammar = "To";
SemanticResultKey resultKey = new SemanticResultKey("brightness", choices);
GrammarBuilder resultContrast = new GrammarBuilder(resultKey);
Choices alternatives = new Choices(changeGrammar, setGrammar);
GrammarBuilder result = new GrammarBuilder(alternatives);
result.Append(brightnessGrammar);
result.Append(toGrammar);
result.Append(resultContrast);
Grammar grammar = new Grammar(result);
grammar.Name = "Set Brightness";
return grammar;
}
示例7: BuildGrammar
public Grammar BuildGrammar()
{
Choices choiceBuilder = new Choices();
// Next
GrammarBuilder nextBuilder = new GrammarBuilder();
nextBuilder.Append(new Choices("next song", "play the next song", "skip this song", "play next song"));
choiceBuilder.Add(nextBuilder);
// Previous
GrammarBuilder prevBuilder = new GrammarBuilder();
prevBuilder.Append(new Choices("last song", "previous song", "play the last song", "play the previous song"));
choiceBuilder.Add(prevBuilder);
// Pause
GrammarBuilder pauseBuilder = new GrammarBuilder();
pauseBuilder.Append(new Choices("pause song", "pause this song", "pause song playback"));
choiceBuilder.Add(pauseBuilder);
// Stop
GrammarBuilder stopBuilder = new GrammarBuilder();
stopBuilder.Append(new Choices("stop song", "stop song playback", "stop the music"));
choiceBuilder.Add(stopBuilder);
// Resume
GrammarBuilder resumeBuilder = new GrammarBuilder();
resumeBuilder.Append(new Choices("resume playback", "resume song", "resume playing"));
choiceBuilder.Add(resumeBuilder);
return new Grammar(new GrammarBuilder(choiceBuilder));
}
示例8: IntroGrammar
public IntroGrammar()
{
Choices majors = new Choices();
majors.Add(new SemanticResultValue("Computer Science", "CSC"));
SemanticResultKey majorKey = new SemanticResultKey(Slots.Major.ToString(), majors);
Choices years = new Choices();
for (int i = 2001; i < 2020; i++)
{
years.Add(new SemanticResultValue(i.ToString(), i));
}
SemanticResultKey year = new SemanticResultKey(Slots.GradYear.ToString(), years);
Choices yesOrNo = new Choices();
yesOrNo.Add(new SemanticResultValue("yes", "yes"));
yesOrNo.Add(new SemanticResultValue("yeah", "yes"));
yesOrNo.Add(new SemanticResultValue("yep", "yes"));
yesOrNo.Add(new SemanticResultValue("no", "no"));
yesOrNo.Add(new SemanticResultValue("nope", "no"));
SemanticResultKey yesNo = new SemanticResultKey(Slots.YesNo.ToString(), yesOrNo);
Choices options = new Choices();
options.Add(majorKey);
options.Add(year);
options.Add(yesNo);
GrammarBuilder builder = new GrammarBuilder();
builder.Append(options);
grammar = new Grammar(builder);
}
示例9: getCommands
private Choices getCommands()
{
var commands = new Choices();
commands.Add(new SemanticResultValue("left", "left"));
commands.Add(new SemanticResultValue("previous", "left"));
commands.Add(new SemanticResultValue("right", "right"));
commands.Add(new SemanticResultValue("next", "right"));
commands.Add(new SemanticResultValue("enter", "enter"));
commands.Add(new SemanticResultValue("accept", "enter"));
commands.Add(new SemanticResultValue("ok", "enter"));
commands.Add(new SemanticResultValue("go", "enter"));
commands.Add(new SemanticResultValue("confirm", "enter"));
commands.Add(new SemanticResultValue("quit", "exit"));
commands.Add(new SemanticResultValue("exit", "exit"));
commands.Add(new SemanticResultValue("back", "exit"));
commands.Add(new SemanticResultValue("cancel", "exit"));
commands.Add(new SemanticResultValue("return", "exit"));
commands.Add(new SemanticResultValue("tv", "input"));
commands.Add(new SemanticResultValue("television", "input"));
commands.Add(new SemanticResultValue("up", "up"));
commands.Add(new SemanticResultValue("more", "up"));
commands.Add(new SemanticResultValue("higher", "up"));
commands.Add(new SemanticResultValue("down", "down"));
commands.Add(new SemanticResultValue("less", "down"));
commands.Add(new SemanticResultValue("lower", "down"));
return commands;
}
示例10: Main
static void Main(string[] args)
{
try
{
ss.SetOutputToDefaultAudioDevice();
Console.WriteLine("\n(Speaking: I am awake)");
ss.Speak("I am awake");
CultureInfo ci = new CultureInfo("en-us");
sre = new SpeechRecognitionEngine(ci);
sre.SetInputToDefaultAudioDevice();
sre.SpeechRecognized += sre_SpeechRecognized;
Choices ch_StartStopCommands = new Choices();
ch_StartStopCommands.Add("Alexa record");
ch_StartStopCommands.Add("speech off");
ch_StartStopCommands.Add("klatu barada nikto");
GrammarBuilder gb_StartStop = new GrammarBuilder();
gb_StartStop.Append(ch_StartStopCommands);
Grammar g_StartStop = new Grammar(gb_StartStop);
sre.LoadGrammarAsync(g_StartStop);
sre.RecognizeAsync(RecognizeMode.Multiple); // multiple grammars
while (done == false) { ; }
Console.WriteLine("\nHit <enter> to close shell\n");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
示例11: VoiceSelect
public VoiceSelect()
{
precision = .5;
newWordReady = false;
RecognizerInfo ri = GetKinectRecognizer();
SpeechRecognitionEngine tempSpeechRec;
tempSpeechRec = new SpeechRecognitionEngine(ri.Id);
var grammar = new Choices();
grammar.Add("select one", "SELECT ONE", "Select One");
grammar.Add("select two", "SELECT TWO", "Select Two");
grammar.Add("pause", "PAUSE");
grammar.Add("exit", "EXIT");
grammar.Add("single player", "SINGLE PLAYER");
grammar.Add("co op mode", "CO OP MODE");
grammar.Add("settings", "SETTINGS");
grammar.Add("instructions", "INSTRUCTIONS");
grammar.Add("statistics", "STATISTICS");
grammar.Add("Main Menu", "MAIN MENU");
grammar.Add("resume", "RESUME");
grammar.Add("restart level", "RESTART LEVEL");
grammar.Add("replay", "REPLAY");
grammar.Add("next", "NEXT");
grammar.Add("Easy", "EASY");
grammar.Add("Hard", "HARD");
/*
grammar.Add("level one");
grammar.Add("level two");
grammar.Add("level three");
grammar.Add("level four");
grammar.Add("level five");
grammar.Add("level six");
grammar.Add("player one left");
grammar.Add("player one right");
grammar.Add("player two left");
grammar.Add("player two right");
grammar.Add("room low");
grammar.Add("room medium");
grammar.Add("room high");
grammar.Add("sounds on");
grammar.Add("sounds off");
grammar.Add("reset stats");
*/
var gb = new GrammarBuilder { Culture = ri.Culture };
gb.Append(grammar);
// Create the actual Grammar instance, and then load it into the speech recognizer.
var g = new Grammar(gb);
tempSpeechRec.LoadGrammar(g);
tempSpeechRec.SpeechRecognized += phraseRecognized;
tempSpeechRec.SpeechHypothesized += phraseHyphothesized;
tempSpeechRec.SpeechRecognitionRejected += phraseRejected;
speechRec = tempSpeechRec;
}
示例12: VoiceInput
public VoiceInput()
{
recognizer = new SpeechRecognitionEngine(new CultureInfo("en-US"));
recognizer.SetInputToDefaultAudioDevice();
Choices choices = new Choices();
foreach (String command in commands)
{
choices.Add(command);
}
choices.Add(startListening);
choices.Add(stopListening);
choices.Add(stop);
/*choices.Add("Close");
choices.Add("Left");
choices.Add("Right");
choices.Add("Tilt Left");
choices.Add("Tilt Right");
choices.Add("Move");
choices.Add("Back");
choices.Add("Move Up");
choices.Add("Down");
choices.Add("Exit");
choices.Add("Stop");
choices.Add("Start Listening");
choices.Add("Stop Listening");*/
Grammar grammar = new Grammar(new GrammarBuilder(choices));
recognizer.LoadGrammar(grammar);
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognized);
recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
示例13: CreateSpeechRecognizer
//here is the fun part: create the speech recognizer
private SpeechRecognitionEngine CreateSpeechRecognizer()
{
//set recognizer info
RecognizerInfo ri = GetKinectRecognizer();
//create instance of SRE
SpeechRecognitionEngine sre;
sre = new SpeechRecognitionEngine(ri.Id);
//Now we need to add the words we want our program to recognise
var grammar = new Choices();
grammar.Add("Record");
grammar.Add("Store");
grammar.Add("Replay");
grammar.Add("Stop");
grammar.Add("Learn");
grammar.Add("Finish");
//set culture - language, country/region
var gb = new GrammarBuilder { Culture = ri.Culture };
gb.Append(grammar);
//set up the grammar builder
var g = new Grammar(gb);
sre.LoadGrammar(g);
//Set events for recognizing, hypothesising and rejecting speech
sre.SpeechRecognized += SreSpeechRecognized;
sre.SpeechHypothesized += SreSpeechHypothesized;
sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;
return sre;
}
示例14: CreateAndLoadGrammarWithObjectsNames
public void CreateAndLoadGrammarWithObjectsNames(string[] objNames)
{
// przesuwanie obiektow z wykorzystaniem nazw
Choices objWithNames = new Choices(objNames);
GrammarBuilder gbMOWN = new GrammarBuilder { Culture = recognizerInfo.Culture };
gbMOWN.Append("move");
gbMOWN.Append(new SemanticResultKey("OWN_MOVE_NAME", objWithNames));
Grammar gMOWN = new Grammar(gbMOWN);
// tworzenie obiektow z wykorzystaniem nazw, bez podawania kierunku
GrammarBuilder gbCOWN = new GrammarBuilder { Culture = recognizerInfo.Culture };
gbCOWN.Append("new");
gbCOWN.Append(new SemanticResultKey("OWN_NEW_NAME", objWithNames));
Grammar gCOWN = new Grammar(gbCOWN);
// usuwanie obiektow z wykorzystaniem nazw
GrammarBuilder gbROWN = new GrammarBuilder { Culture = recognizerInfo.Culture };
gbROWN.Append("remove");
gbROWN.Append(new SemanticResultKey("OWN_REMOVE_NAME", objWithNames));
Grammar gROWN = new Grammar(gbROWN);
// ladujemy wszystkie gramatyki
speechEngine.LoadGrammar(gMOWN);
speechEngine.LoadGrammar(gCOWN);
speechEngine.LoadGrammar(gROWN);
mainEngine.AddTextToLog("SpeechRec: " + "grammars loaded");
}
示例15: Initiate
public override void Initiate(IEnumerable<string> commandKeys)
{
var choices = new Choices();
choices.Add(commandKeys.ToArray());
var gr = new Grammar(new GrammarBuilder(choices));
_mainSpeechRecognitionEngine.RequestRecognizerUpdate();
_mainSpeechRecognitionEngine.LoadGrammar(gr);
_mainSpeechRecognitionEngine.SpeechRecognized += _mainSpeechRecognitionEngine_SpeechRecognized;
try
{
_mainSpeechRecognitionEngine.SetInputToDefaultAudioDevice();
}
catch (Exception exception)
{
base.WriteLine(string.Format("Unable to set default input audio device. Error: {0}", exception.Message), OutputLevel.Error, null);
return;
}
var subChoices = new Choices();
subChoices.Add(new[] { "tab", "enter" });
var subGr = new Grammar(new GrammarBuilder(subChoices));
_subSpeechRecognitionEngine.RequestRecognizerUpdate();
_subSpeechRecognitionEngine.LoadGrammar(subGr);
_subSpeechRecognitionEngine.SpeechRecognized += _subSpeechRecognitionEngine_SpeechRecognized;
_subSpeechRecognitionEngine.SetInputToDefaultAudioDevice();
}