我的 UWP 应用程序中的默认听写语法无法识别语音. [英] Speech is not being recognized with default dictation grammar in my UWP application.

查看:29
本文介绍了我的 UWP 应用程序中的默认听写语法无法识别语音.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UWP 应用程序中的默认听写语法无法识别语音.但是,当我使用程序化列表约束时,它被完美识别.下面是我的代码的语音识别部分,供参考.如果我不评论第 5 行,这可以正常工作.我在下面做错了什么:

Speech is not being recognized with default dictation grammar in my UWP application. However, it is perfectly recognized when I use programmatic list constraint. Below is the speech recognition part of my code for reference. If I do not comment the 5th line, this works fine. Am I doing something wrong below:

            speechRecognizer = new SpeechRecognizer();
            bool PermissionGained = await CheckMicrophonePermission();
            if (PermissionGained)
            {
               //speechRecognizer.Constraints.Add(new SpeechRecognitionListConstraint(Grammar.GrammarCommands.GrammarConstraintList));
               await speechRecognizer.CompileConstraintsAsync();

                //recognize speech input at any point of time 
                speechRecognizer.ContinuousRecognitionSession.ResultGenerated +=
                    async (s, e1) =>
                    {
                        if ((e1.Result != null)) 
                        {
                            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                async () =>
                                {
                                    await ParsespeechCommand(e1.Result);

                                });
                             speechRecognizer.ContinuousRecognitionSession.Resume();
                        }
                    };
                await speechRecognizer.ContinuousRecognitionSession.StartAsync(SpeechContinuousRecognitionMode.PauseOnRecognition);
            }

推荐答案

正如所讨论的,我做了一个演示并对代码进行了一些更改.这是我的代码:

As discussed I made a demo and made some changes from the codes. Here are my codes:

private async void myBtn_Click(object sender, RoutedEventArgs e)
{
        //here I remove the checkPermission process
        var speechRecognizer = new SpeechRecognizer();
        if (true)
        {
            //speechRecognizer.Constraints.Add(new SpeechRecognitionListConstraint(new List<string> { "winffee", "Elvis", "noob" }));
            await speechRecognizer.CompileConstraintsAsync();

            //recognize speech input at any point of time 
            speechRecognizer.ContinuousRecognitionSession.ResultGenerated +=
                async (s, e1) =>
                {
                    if ((e1.Result != null))
                    {
                        await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                            () =>//here I remove the async
                            {
                                var result = e1.Result;//here I remove the method to focus on the e1.Result.
                            });
                        speechRecognizer.ContinuousRecognitionSession.Resume();
                    }
                };
            await speechRecognizer.ContinuousRecognitionSession.StartAsync(SpeechContinuousRecognitionMode.PauseOnRecognition);
        }
}

整个函数是由一个按钮点击事件触发的.并且我对每一个变化位置都做了评论(共3个位置).

The whole function is triggered by a button click event. And I made comment on every change position(totally 3 places).

这篇关于我的 UWP 应用程序中的默认听写语法无法识别语音.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆