UWP连续语音识别

问题描述 投票:1回答:1

我正在使用UWP创建智能镜像应用程序,我希望用户使用他们的语音来控制应用程序。到目前为止,我做了一个简单的程序来测试语音识别,它可以工作,但我想只有当应用程序听到关键词 - “杰森”时,它才会开始将语音转换为文本(我称之为智能镜像杰森) )喜欢:“杰森,给我看一些新闻”,因为之后我会把文字按摩传给LUIS功能。如果句子不以“Jason”开头,则应用程序不会将其转换为文本。我该怎么做才能实现它? “

    private SpeechRecognizer contSpeechRecognizer;
    private CoreDispatcher dispatcher;

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
        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.Text = args.Result.Text;
        });
    }
c# uwp voice-recognition
1个回答
1
投票

如果您只想使用“Jason”作为触发器,则可以添加

if(speechResult.Contains("Jason")||speechResult.Contains("jason"))
{//Pass the Result to LUIS}
© www.soinside.com 2019 - 2024. All rights reserved.