本文整理汇总了C#中SpeechRecognizer.LoadGrammar方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechRecognizer.LoadGrammar方法的具体用法?C# SpeechRecognizer.LoadGrammar怎么用?C# SpeechRecognizer.LoadGrammar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpeechRecognizer
的用法示例。
在下文中一共展示了SpeechRecognizer.LoadGrammar方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, EventArgs e)
{
SpeechRecognizer r = new SpeechRecognizer();
Choices c = new Choices();
c.Add(new String[] {"haha","hahaha","hahahaha","hahahahaha","hahahahahaha","hahahahahahaha","hahahahahahahaha","hahahahahahahahahah"});
GrammarBuilder gb = new GrammarBuilder();
gb.Append(c);
Grammar g = new Grammar(gb);
r.LoadGrammar(g);
r.SpeechRecognized+=new EventHandler<SpeechRecognizedEventArgs>(r_SpeechRecognized);
}
示例2: SpeechInput
public SpeechInput()
{
SpeechRecognizer recognizer = new SpeechRecognizer();
Choices numbers = new Choices();
numbers.Add(this.allowedPhrases);
GrammarBuilder gb = new GrammarBuilder();
gb.Append(numbers);
Grammar g = new Grammar(gb);
recognizer.LoadGrammar(g);
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(this.Sre_SpeechRecognized);
}
示例3: VoiceCommandRecognizer
public VoiceCommandRecognizer()
{
recognizer = new SpeechRecognizer();
Choices commands = new Choices();
commands.Add(new string[] { "test", "example" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(commands);
Grammar g = new Grammar(gb);
recognizer.LoadGrammar(g);
handler = new EventHandler<SpeechRecognizedEventArgs>(recognitionHandler);
//per ora lo faccio così, ma è assolutamente da CAMBIARE
StartRecognition();
}
示例4: Run
public static void Run()
{
// Initialize an instance of the shared recognizer.
using (SpeechRecognizer recognizer = new SpeechRecognizer())
{
// Create and load a sample grammar.
Grammar testGrammar =
new Grammar(new GrammarBuilder("testing testing"));
testGrammar.Name = "Test Grammar";
recognizer.LoadGrammar(testGrammar);
// Attach event handlers for recognition events.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(
SpeechRecognizedHandler);
recognizer.EmulateRecognizeCompleted +=
new EventHandler<EmulateRecognizeCompletedEventArgs>(
EmulateRecognizeCompletedHandler);
completed = false;
// Start asynchronous emulated recognition.
// This matches the grammar and generates a SpeechRecognized event.
recognizer.EmulateRecognizeAsync("testing testing");
// Wait for the asynchronous operation to complete.
while (!completed)
{
Thread.Sleep(333);
}
completed = false;
// Start asynchronous emulated recognition.
// This does not match the grammar or generate a SpeechRecognized event.
recognizer.EmulateRecognizeAsync("testing one two three");
// Wait for the asynchronous operation to complete.
while (!completed)
{
Thread.Sleep(333);
}
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
示例5: WinRecog
internal WinRecog( )
{
try
{
rec = new SpeechRecognizer();
dGrammar = new DictationGrammar();
rec.LoadGrammar(dGrammar);
cGrammars = new Dictionary<string, Grammar>();
}
catch (Exception e)
{
rec = null;
Logger.Log("Speech recognition disabled, " + e.Message,
Helpers.LogLevel.Warning);
return;
}
}
示例6: button1_Click
private void button1_Click(object sender, EventArgs e)
{
// Create a Speech Recognition Engine instance
// Notice: Need to add reference "System.Speech" in your project. Right click on the Reference on your Solution Explorer and add.
// Notice: Include namespace System.Speech.Recognition
SpeechRecognizer recognizer = new SpeechRecognizer();
// Create a grammar with several words. We need
Choices colors = new Choices();
colors.Add(new String[] { "right wing", "left wing", "vertical stabilizer", "elevator", "winglet", "horizontal stabilizer", "engine", "slats", "transmission" });
// Create a GrammarBuilder object and append the Choices object
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create a new Grammar and load it into speech recognition engine
Grammar g = new Grammar(gb);
recognizer.LoadGrammar(g);
// Register a handler for the SpeechRecognized event, which defined in ser_SpeechRecognized
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(ser_SpeechRecognized);
}
示例7: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
// Create a new SpeechRecognitionEngine instance.
SpeechRecognizer recognizer = new SpeechRecognizer();
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add(new string[] { "red", "green", "blue" });
// Create a GrammarBuilder object and append the Choices object.
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the Grammar instance and load it into the speech recognition engine.
Grammar g = new Grammar(gb);
recognizer.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
}
示例8: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.ShowBalloonTip(50);
notifyIcon1.ContextMenuStrip = contextMenuStrip1;
SpeechRecognizer sr = new SpeechRecognizer();
Choices commands = new Choices();
commands.Add(new string[] { "up", "down", "right", "left", "ok", "back", "tab","escape", "close" });
GrammarBuilder gbuilder = new GrammarBuilder();
gbuilder.Append(commands);
// Create the Grammar instance.
Grammar g = new Grammar(gbuilder);
sr.LoadGrammar(g);
g.Priority = 127;
sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);
}
示例9: MainWindow
public MainWindow()
{
InitializeComponent();
InitializeUI();
Speech = new SpeechRecognizer();
Choices commands = new Choices();
commands.Add(new string[]
{
"add feed", "add channel", "select article", "read article", "unread article", "next article", "previous article",
"view main", "view topic", "view map",
"save", "load", "exit"
});
GrammarBuilder gb = new GrammarBuilder();
gb.Append(commands);
Grammar = new Grammar(gb);
Speech.LoadGrammar(Grammar);
Speech.SpeechRecognized += Speech_SpeechRecognized;
}
示例10: RecordButton2_Click
private void RecordButton2_Click(object sender, EventArgs e)
{
recognizer = new SpeechRecognizer();
g = CreateLogInGrammar();
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(plane_ser_SpeechRecognized);
recognizer.LoadGrammar(g);
}
示例11: Grid_Loaded
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
SpeechRecognizer sr = new SpeechRecognizer();
SpeechRecognizer recognizer = new SpeechRecognizer();
Choices colors = new Choices();
colors.Add(new string[] { "banana", "apple", "car" });
// Create a GrammarBuilder object and append the Choices object.
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the Grammar instance and load it into the speech recognition engine.
Grammar g = new Grammar(gb);
recognizer.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
}
示例12: Init
public void Init()
{
recognizer = new SpeechRecognizer();
recognizer.Enabled = true;
recognizer.SpeechRecognized += (s, args) =>
{
foreach (RecognizedWordUnit word in args.Result.Words)
{
if (word.Confidence > 0.5f)
message += word.Text + " ";
}
};
recognizer.LoadGrammar(new DictationGrammar());
//recognitionEngine = new SpeechRecognitionEngine();
//recognitionEngine.SetInputToDefaultAudioDevice();
//recognitionEngine.SpeechRecognized += (s, args) =>
//{
// foreach (RecognizedWordUnit word in args.Result.Words)
// {
// if (word.Confidence > 0.5f)
// message += word.Text + " ";
// }
//};
//recognitionEngine.LoadGrammar(new DictationGrammar());
if (!string.IsNullOrEmpty(message) && outputMessage != message)
{
outputMessage = message;
Console.WriteLine(message);
}
}
示例13: button2_Click
private void button2_Click(object sender, EventArgs e)
{
recognizer = new SpeechRecognizer();
g = CreateFormGrammar();
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(jobType_ser_SpeechRecognized);
recognizer.LoadGrammar(g);
}