Пример #1
0
        private async void Listen()
        {
            if (!busy)
            {
                busy = true;
                // Initialize the SpeechRecognizerUI object.
                recoWithUI = new SpeechRecognizerUI();

                // Query for a recognizer that recognizes French as spoken in France.
                IEnumerable<SpeechRecognizerInformation> recognizers = from recognizerInfo in InstalledSpeechRecognizers.All
                                                                       select recognizerInfo;

                // Set the recognizer to the top entry in the query result.
                recoWithUI.Recognizer.SetRecognizer(recognizers.ElementAt(0));

                // Create a string array of French numbers.
                string[] settings = (from MarketCat cat in listOfCats.ToList()
                                     select cat.Title).ToArray();

                // Create a list grammar from the string array and add it to the grammar set.
                recoWithUI.Recognizer.Grammars.AddGrammarFromList("categories", settings);

                string listenText = "";
                string exampleText = "";
                for (int i = 0; i < settings.Length; i++)
                {
                    listenText += settings[i];
                    exampleText += " " + settings[i];
                }
                // Display text to prompt the user's input.
                recoWithUI.Settings.ListenText = "Category Between: ";

                recoWithUI.Settings.ReadoutEnabled = false;
                // Give an example of ideal speech input.
                recoWithUI.Settings.ExampleText = exampleText;

                // Load the grammar set and start recognition.
                SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
                string action = recoResult.RecognitionResult.Text;
                SpeechSynthesizer ss = new SpeechSynthesizer();
                VoiceInformation vi = InstalledVoices.All.Where(v => v.Language == "en-EN" && v.Gender == VoiceGender.Male).FirstOrDefault();
                ss.SetVoice(vi);
                await ss.SpeakTextAsync("I'm looking for " + action + "!");
                MarketCat chooseCat = (from MarketCat cat in listOfCats.ToList()
                                       where cat.Title == action
                                       select cat).FirstOrDefault();
                chooseAppsPreview = CreateAppsPreview(chooseCat);
                CategorieTitle.Text = chooseCat.Title;
                AppsPreviewContent.Children.Clear();
                AppsPreviewContent.Children.Add(chooseAppsPreview);
                chooseAppsPreview.load();

                chooseAppsPreview.CompletedEvent+= (e, o) =>
                {
                    sayAppName();
                };
               
            }
            busy = false;
        }
Пример #2
0
 private AppsPreview CreateAppsPreview(MarketCat Cat)
 {
     XMLLoader loader = new XMLLoader();
     XMLParser parser = new MarketAppXMLParserFromMP();
     XMLLoader previewLoader = new XMLLoader();
     XMLParser previewParser = new MarketAppXMLParser();
     Uri uri = URIModel.Instance.getBaseAppsUri();
     AppsPreview RandomAppsPreview;
     RandomAppsPreview = new AppsPreview();
     RandomAppsPreview.URI = uri;
     RandomAppsPreview.Category = Cat;
     RandomAppsPreview.PreviewLoader = previewLoader;
     RandomAppsPreview.Loader = loader;
     RandomAppsPreview.PreviewParser = previewParser;
     RandomAppsPreview.Parser = parser;
     RandomAppsPreview.UrlGetter = URIModel.Instance.getRandomWithCat;
     RandomAppsPreview.ErrorEvent += RandomAppsPreview_ErrorEvent;
     return RandomAppsPreview;
 }