1

我在 MvvmCross Xamarin.Forms 解决方案中实现了 Shiny Speech Recognition 插件。

=> https://github.com/shinyorg/shiny

Nuget => https://www.nuget.org/packages/Shiny.SpeechRecognition/1.0.0.357-beta

我正在尝试在 MvxViewModel 构造函数中使用 ISpeechRecognition,因为它在 GitHub 上的 Prism Sample 上工作。

=> https://github.com/shinyorg/shinysamples/tree/master/Samples/Speech

我已经实现了 MvvmCross 的集成插件。=> https://www.nuget.org/packages/Shiny.Integrations.MvvmCross/1.0.0.375-beta

现在我想知道如何使用语音识别服务。

我可以有类似的东西:

public YourViewsModel(IMvxNavigationService navigationService, ISpeechRecognizer speechRecognizer)
        {
            _navigationService = navigationService;
            _speechRecognizer = speechRecognizer;
        }

或者可能是具有寄存器依赖的依赖注入,例如:

Mvx.IoCProvider.LazyConstructAndRegisterSingleton<ISpeechRecognizer, SpeechRecognizerImpl>();

我想知道,如果有人已经有 Shiny 插件 Xamarin.Forms 是如何使用该服务的?

我创建了一个启动 Shiny 类。

public class InitializeShiny : ShinyStartup
    {
        public override void ConfigureServices(IServiceCollection services)
        {
            services.UseSpeechRecognition(); // implement Speech Recognition service.
        }
    }

然后初始化一个顶级自定义应用程序定义。在 OnCreate() 方法中:

// Initialisation Shiny Plugin.
            AndroidShinyHost.Init(Application, new InitializeShiny(), services =>
            {
                services.UseSpeechRecognition();
            });

所以现在在我们的 ViewModel 中,我们可以从 ShinyMvxViewModel 继承来启动 ViewModel。

公共类 YourViewModel : ShinyMvxViewModel {}

一切正常。该应用程序启动没有问题。

这不起作用:

public YourViewsModel(IMvxNavigationService navigationService, ISpeechRecognizer speechRecognizer)

我可以创建构造函数,因为它无法识别 ISpeechRecognizer。

仅有的

public YourViewsModel(IMvxNavigationService navigationService)

正在工作中。

这也不起作用:

private ISpeechRecognizer _speechRecognizer;

_speechRecognizer = Mvx.IoCProvider.Resolve<ISpeechRecognizer>();

错误是它没有 ISpeechRecognizer 的实现。我不知道。

我已经在覆盖方法中初始化了惰性寄存器。

protected override void InitializePlatformServices()

Mvx.IoCProvider.LazyConstructAndRegisterSingleton<ISpeechRecognizer, SpeechRecognizerImpl>();

感谢您的帮助。

泽比菲尔

4

0 回答 0