基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Speech.Recognition;
|
||||
using System.Text;
|
||||
|
||||
namespace Lskj.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// 语音操作类
|
||||
/// </summary>
|
||||
public sealed class SpeechHelp
|
||||
{
|
||||
private string Text;
|
||||
private SpeechRecognitionEngine recognizer;
|
||||
private DictationGrammar dictationGrammar;
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
recognizer.RecognizeAsync(RecognizeMode.Multiple);
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
recognizer.RecognizeAsyncStop();
|
||||
}
|
||||
|
||||
public void SRecognition(string[] fg, int i) //创建关键词语列表
|
||||
{
|
||||
CultureInfo myCIintl = new CultureInfo("zh-CN");
|
||||
foreach (RecognizerInfo config in SpeechRecognitionEngine.InstalledRecognizers())//获取所有语音引擎
|
||||
{
|
||||
Console.WriteLine(config.Culture.EnglishName);
|
||||
if (config.Culture.Equals(myCIintl))
|
||||
{
|
||||
recognizer = new SpeechRecognitionEngine(config);
|
||||
break;
|
||||
}//选择识别引擎
|
||||
}
|
||||
if (recognizer != null)
|
||||
{
|
||||
InitializeSpeechRecognitionEngine(fg);//初始化语音识别引擎
|
||||
dictationGrammar = new DictationGrammar();
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeSpeechRecognitionEngine(string[] s)
|
||||
{
|
||||
// Create and load a dictation grammar.
|
||||
//recognizer.LoadGrammar(new DictationGrammar());
|
||||
|
||||
// Configure input to the speech recognizer.
|
||||
recognizer.SetInputToDefaultAudioDevice();
|
||||
|
||||
// Modify the initial silence time-out value.
|
||||
recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(5);
|
||||
|
||||
GrammarBuilder GB = new GrammarBuilder();
|
||||
GB.Append("选择");
|
||||
GB.Append(new Choices(new string[] { "红色", "绿色" }));
|
||||
Grammar G = new Grammar(GB);
|
||||
Console.WriteLine(G.RuleName);
|
||||
G.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(G_SpeechRecognized);
|
||||
recognizer.LoadGrammar(G);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 语音操作erp数据
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void G_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
|
||||
{
|
||||
Text = e.Result.Text;
|
||||
switch (e.Result.Text)
|
||||
{
|
||||
//case "选择红色":
|
||||
// BackColor = Color.Red;
|
||||
// button2.BackColor = BackColor;
|
||||
// break;
|
||||
//case "选择绿色":
|
||||
// BackColor = Color.Green;
|
||||
// button2.BackColor = BackColor;
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user