本文整理汇总了C#中GrammarBuilder类的典型用法代码示例。如果您正苦于以下问题:C# GrammarBuilder类的具体用法?C# GrammarBuilder怎么用?C# GrammarBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GrammarBuilder类属于命名空间,在下文中一共展示了GrammarBuilder类的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: MainWindow
public MainWindow()
{
InitializeComponent();
var config = new JsonConfigHandler( System.IO.Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData ), "LeagueTag" ) );
//config.Populate();
config.Save();
//config.Save(
return;
var engine = new SpeechRecognitionEngine();
var builder = new GrammarBuilder();
builder.Append( "tag" );
builder.Append( new Choices( "baron", "dragon" ) );
engine.RequestRecognizerUpdate();
engine.LoadGrammar( new Grammar( builder ) );
engine.SpeechRecognized += engine_SpeechRecognized;
engine.SetInputToDefaultAudioDevice();
engine.RecognizeAsync( RecognizeMode.Multiple );
CompositionTarget.Rendering += CompositionTarget_Rendering;
this.DataContext = this;
}
示例3: 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);
}
示例4: initRS
public void initRS()
{
try
{
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new CultureInfo("en-US"));
var words = new Choices();
words.Add("Hello");
words.Add("Jump");
words.Add("Left");
words.Add("Right");
var gb = new GrammarBuilder();
gb.Culture = new System.Globalization.CultureInfo("en-US");
gb.Append(words);
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception e)
{
label1.Text = "init RS Error : " + e.ToString();
}
}
示例5: addCommand
private GrammarBuilder addCommand()
{
//<pleasantries> <command> <CLASS> <prep> <Time><year>
//Pleasantries: I'd like to, please, I want to, would you
//Command: Add, Remove
//Class: a class, this class, that class, that other class
//When: to Spring 2012
Choices commands = new Choices();
SemanticResultValue commandSRV;
commandSRV = new SemanticResultValue("add", (int)CommandTypes.Add);
commands.Add(commandSRV);
commandSRV = new SemanticResultValue("take", (int)CommandTypes.Add);
commands.Add(commandSRV);
commandSRV = new SemanticResultValue("put", (int)CommandTypes.Add);
commands.Add(commandSRV);
SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands);
// put the whole command together
GrammarBuilder finalCommand = new GrammarBuilder();
finalCommand.Append(this.pleasantries, 0, 1);
finalCommand.Append(commandSemKey);
finalCommand.Append(this.course, 0, 1);
finalCommand.Append(this.semester, 0, 1);
return finalCommand;
}
示例6: 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));
}
示例7: LoadCurrentSyllabus
internal void LoadCurrentSyllabus(SyllabusTracker syllabusTracker)
{
if (_speechRecognitionEngine == null) return; // not currently running recognition
_speechRecognitionEngine.RequestRecognizerUpdate();
_speechRecognitionEngine.UnloadAllGrammars();
// new choices consolidation for commands - one command per syllabus file line
var commandLoad = new Choices();
foreach (var baseSyllabus in syllabusTracker.Syllabi)
{
foreach (var command in baseSyllabus.Commands)
{
commandLoad.Add(command);
}
}
// add commands - should be per input language, but now English
VoiceCommands.AddCommands(commandLoad);
var gBuilder = new GrammarBuilder();
gBuilder.Append(commandLoad);
var grammar = new Grammar(gBuilder) { Name = "Syllabus" };
_speechRecognitionEngine.LoadGrammar(grammar);
var dictgrammar = new DictationGrammar("grammar:dictation#pronunciation") { Name = "Random" };
_speechRecognitionEngine.LoadGrammar(dictgrammar);
}
示例8: 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();
}
}
示例9: load_listen
public void load_listen(VI_Profile profile, VI_Settings settings, ListView statusContainer)
{
this.profile = profile;
this.settings = settings;
this.statusContainer = statusContainer;
vi_syn = profile.synth;
vi_syn.SelectVoice(settings.voice_info);
vi_sre = new SpeechRecognitionEngine(settings.recognizer_info);
GrammarBuilder phrases_grammar = new GrammarBuilder();
List<string> glossory = new List<string>();
foreach (VI_Phrase trigger in profile.Profile_Triggers)
{
glossory.Add(trigger.value);
}
if (glossory.Count == 0)
{
MessageBox.Show("You need to add at least one Trigger");
return;
}
phrases_grammar.Append(new Choices(glossory.ToArray()));
vi_sre.LoadGrammar(new Grammar(phrases_grammar));
//set event function
vi_sre.SpeechRecognized += phraseRecognized;
vi_sre.SpeechRecognitionRejected += _recognizer_SpeechRecognitionRejected;
vi_sre.SetInputToDefaultAudioDevice();
vi_sre.RecognizeAsync(RecognizeMode.Multiple);
}
示例10: 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;
}
示例11: CreateSpeechRecognizer
//Speech recognizer
private SpeechRecognitionEngine CreateSpeechRecognizer()
{
RecognizerInfo ri = GetKinectRecognizer();
SpeechRecognitionEngine sre;
sre = new SpeechRecognitionEngine(ri.Id);
//words we need the program to recognise
var grammar = new Choices();
grammar.Add(new SemanticResultValue("moustache", "MOUSTACHE"));
grammar.Add(new SemanticResultValue("top hat", "TOP HAT"));
grammar.Add(new SemanticResultValue("glasses", "GLASSES"));
grammar.Add(new SemanticResultValue("sunglasses", "SUNGLASSES"));
grammar.Add(new SemanticResultValue("tie", "TIE"));
grammar.Add(new SemanticResultValue("bow", "BOW"));
grammar.Add(new SemanticResultValue("bear", "BEAR"));
//etc
var gb = new GrammarBuilder { Culture = ri.Culture };
gb.Append(grammar);
var g = new Grammar(gb);
sre.LoadGrammar(g);
//Events for recognising and rejecting speech
sre.SpeechRecognized += SreSpeechRecognized;
sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;
return sre;
}
示例12: InicializeSpeechRecognize
public void InicializeSpeechRecognize()
{
RecognizerInfo ri = GetKinectRecognizer();
if (ri == null)
{
throw new RecognizerNotFoundException();
}
try
{
_sre = new SpeechRecognitionEngine(ri.Id);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
var choises = new Choices();
foreach(CommandSpeechRecognition cmd in _commands.Values)
{
choises.Add(cmd.Choise);
}
var gb = new GrammarBuilder {Culture = ri.Culture};
gb.Append(choises);
var g = new Grammar(gb);
_sre.LoadGrammar(g);
_sre.SpeechRecognized += SreSpeechRecognized;
_sre.SpeechHypothesized += SreSpeechHypothesized;
_sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;
}
示例13: 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;
}
示例14: CreateGrammar
public void CreateGrammar()
{
var b = new GrammarBuilder();
b.Append(Config.StopListening);
Grammar = new Grammar(b);
}
示例15: SpeechRecogniser
public SpeechRecogniser()
{
RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();
if (ri == null)
return;
sre = new SpeechRecognitionEngine(ri.Id);
// Build a simple grammar of shapes, colors, and some simple program control
var instruments = new Choices();
foreach (var phrase in InstrumentPhrases)
instruments.Add(phrase.Key);
var objectChoices = new Choices();
objectChoices.Add(instruments);
var actionGrammar = new GrammarBuilder();
//actionGrammar.AppendWildcard();
actionGrammar.Append(objectChoices);
var gb = new GrammarBuilder();
gb.Append(actionGrammar);
var g = new Grammar(gb);
sre.LoadGrammar(g);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SpeechHypothesized += sre_SpeechHypothesized;
sre.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);
var t = new Thread(StartDMO);
t.Start();
valid = true;
}