uwp语音识别不同级别控制

时间:2017-08-02 09:10:32

标签: c# uwp speech-recognition

我正在使用UWP创建语音交互式应用。哪些可以显示新闻和天气信息,也可以播放音乐(我已经完成了那部分),但我在语音识别方面遇到了一些问题:

我期望的功能:  第一个命令必须包括" Jason"要激活应用程序,之后你只需要说你想要的功能就不再需要添加Jason了(比如"给我看一些新闻。"),30秒后,这个激活部分结束,你的命令需要添加" Jason"再次激活App。

到目前为止我所取得的功能: 可以持续识别用户的讲话,但每个命令都必须有" Jason"触发功能(比如" Jason,给我看一些新闻。") 以下是我使用的代码。

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
        SpeechRecognizer contSpeechRecognizer =  new Windows.Media.SpeechRecognition.SpeechRecognizer();
        await contSpeechRecognizer.CompileConstraintsAsync();
        contSpeechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;


        contSpeechRecognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout = TimeSpan.FromDays(1);
        contSpeechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;


        await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
    }
    private async void ContinuousRecognitionSession_Completed(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionCompletedEventArgs args)
    {
        await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
    }
    private async void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
    {
        await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            speechResult = args.Result.Text; 
            try
            {

                if (speechResult.Contains("jason"))
                {
                    Functions();//Control functions
                }
            catch
            {
            }
        });
    }

问题:1。如何改变以达到预期的功能? 2.语法可以解决这个问题吗? 3.以及如何添加语法?

0 个答案:

没有答案