我想使用kinect sdk语音识别从Metro UI运行应用程序。 例如,当我说这个词:新闻时,它将从Metro UI运行News的应用程序。使用Kinect语音识别来运行Metro GUI应用程序
感谢大家!
问候!
我想使用kinect sdk语音识别从Metro UI运行应用程序。 例如,当我说这个词:新闻时,它将从Metro UI运行News的应用程序。使用Kinect语音识别来运行Metro GUI应用程序
感谢大家!
问候!
首先,你需要与音频流的连接,并开始听:
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,承认):
private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
this.RecognizedWord = e.Result.Text;
if (e.Result.Confidence > 0.65) InterpretCommand(e);
}
知道所有你所要做的就是写InterpretCommand
方法,做任何你想要的(如跑步一个地铁应用程序;))。如果您在一个词典中有多个词,该方法必须解析所识别的文本,并确认这是被识别的新闻词。
Here你可以在Kinect上下载一本好书的样本:Beginning Kinect Programming with the Microsoft Kinect SDK(不幸的是,这本书本身并不是免费的)。在文件夹Chapter7 \ PutThatThereComplete \你有一个使用音频的例子,你可以从中得到启发。
尝试检查这个项目 - Kinect your Metro Style App
完美....我按照您的代码段...我运行的代码,它的正常工作......现在我已经在我的面前地铁GUI,但当我说“新闻”它什么也没有运行......我想模拟点击图标新闻...如何做到这一点? – Antonio