【发布时间】:2012-07-02 23:03:13
【问题描述】:
我想使用 kinect sdk 语音识别从 Metro UI 运行应用程序。 例如,当我说:News 这个词时,它会从 Metro UI 运行 News 的应用程序。
谢谢大家!
问候!
【问题讨论】:
标签: c# microsoft-metro kinect
我想使用 kinect sdk 语音识别从 Metro UI 运行应用程序。 例如,当我说:News 这个词时,它会从 Metro UI 运行 News 的应用程序。
谢谢大家!
问候!
【问题讨论】:
标签: c# microsoft-metro kinect
首先您需要与音频流建立连接并开始收听:
private KinectAudioSource source;
private SpeechRecognitionEngine sre;
private Stream stream;
private void CaptureAudio()
{
this.source = KinectSensor.KinectSensors[0].AudioSource;
this.source.AutomaticGainControlEnabled = false;
this.source.EchoCancellationMode = EchoCancellationMode.CancellationOnly;
this.source.BeamAngleMode = BeamAngleMode.Adaptive;
RecognizerInfo info = SpeechRecognitionEngine.InstalledRecognizers()
.Where(r => r.Culture.TwoLetterISOLanguageName.Equals("en"))
.FirstOrDefault();
if (info == null) { return; }
this.sre = new SpeechRecognitionEngine(info.Id);
if(!isInitialized) CreateDefaultGrammars();
sre.LoadGrammar(CreateGrammars()); //Important step
this.sre.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>
(sre_SpeechRecognized);
this.sre.SpeechHypothesized +=
new EventHandler<SpeechHypothesizedEventArgs>
(sre_SpeechHypothesized);
this.stream = this.source.Start();
this.sre.SetInputToAudioStream(this.stream, new SpeechAudioFormatInfo(
EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
this.sre.RecognizeAsync(RecognizeMode.Multiple);
}
首先,您可以在示例中看到一个重要的步骤sre.LoadGrammar(CreateGrammars()); 创建并加载语法,因此您必须创建方法CreateGrammars():
private Grammar CreateGrammars()
{
var KLgb = new GrammarBuilder();
KLgb.Culture = sre.RecognizerInfo.Culture;
KLgb.Append("News");
return Grammar(KLgb);
}
上面的示例为“新闻”这个词创建了一个语法监听。一旦被识别(在您的语法中所说的单词的概率高于阈值),语音识别器引擎 (sre) 就会引发 SpeechRecognized 事件。
当然,您需要为这两个事件(Hypothetize、Recognize)添加正确的处理程序:
private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
this.RecognizedWord = e.Result.Text;
if (e.Result.Confidence > 0.65) InterpretCommand(e);
}
知道您所要做的就是编写 InterpretCommand 方法,它可以做任何您想做的事情(如运行 Metro 应用程序;))。如果字典中有多个单词,则该方法必须解析识别的文本并验证这是被识别的单词 news。
Here你可以下载一本关于 Kinect 的好书的样本:Beginning Kinect Programming with the Microsoft Kinect SDK(不幸的是这本书本身不是免费的)。在 Chapter7\PutThatThereComplete\ 文件夹中,您有一个使用音频的示例,您可以从中获得灵感。
【讨论】: