1

I have implemented the Shiny Speech Recognition plugin in a MvvmCross Xamarin.Forms solution.

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

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

I'm trying to use the ISpeechRecognition in the MvxViewModel constructor as it work on the Prism Sample on GitHub.

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

I have implemented The integration plugin for MvvmCross. => https://www.nuget.org/packages/Shiny.Integrations.MvvmCross/1.0.0.375-beta

Now I want to know how I can use the Speech Recognition service.

Can I have something like:

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

Or maybe dependency injection with the register dependence like:

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

What I want to know, if someone have already Shiny plugin Xamarin.Forms is how used the service ?

I have create a startup Shiny class.

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

Then initialize a top level custom Application definition. In the OnCreate() method:

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

So now in our ViewModel we can inherit from ShinyMvxViewModel to start the ViewModel.

public class YourViewModel : ShinyMvxViewModel {}

All is working perfectly. The application is launched without problem.

This doesn't work:

public YourViewsModel(IMvxNavigationService navigationService, ISpeechRecognizer speechRecognizer)

I can create the constructor because it doesn't recognize ISpeechRecognizer.

Only

public YourViewsModel(IMvxNavigationService navigationService)

is working.

This doesn't work too:

private ISpeechRecognizer _speechRecognizer;

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

The error is it doesn't have implemention for ISpeechRecognizer. I don't know.

I have initialise the lazy register in the override method.

protected override void InitializePlatformServices()

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

Thank for the help.

Zebiphire

Zebiphire
  • 21
  • 3
  • Could you please share the code of your ISpeechRecognizer and SpeechRecognizer(SpeechRecognizerImpl in your case) classes as well? Does the SpeechRecognizer class inherit from the ISpeechRecognizer? What version of MVVMCross are you using? Did you put the Mvx.LazyConstructAndRegisterSingleton(); in the InitializeIoC() override of the Setup.cs class? – Saamer Oct 07 '19 at 15:09
  • If you did all that and also have a private field `private IFileStorageService _speechRecognizer;` You should be able to do this `public YourViewsModel(IMvxNavigationService navigationService, ISpeechRecognizer speechRecognizer){_speechRecognizer=speechRecognizer;...}` without issues – Saamer Oct 07 '19 at 15:09

0 Answers0