Esempio n. 1
0
 private async void Initialize()
 {
     SelectedBodies = new ObservableCollection<CelestialBody>();
     dataManager = new DataManager();
     if (this.IsInDesignMode)
     {
         system = dataManager.LoadSampleData();
     }
     else
     {
         system = await dataManager.LoadDataAsync();
         await InitSpeechAsync();
         InitIO();
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes speech recognition and begins listening.
        /// </summary>
        /// <param name="system">
        /// The <see cref="CelestialSystem"/> used to build voice commands and return results.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that yields the result of the operation.
        /// </returns>
        public async Task<SpeechRecognitionResultStatus> InitializeAsync(CelestialSystem system)
        {
            // Validate
            if (isInitialized) { throw new InvalidOperationException("Already initialized."); }
            if (system == null) throw new ArgumentNullException("system");

            // Store
            this.system = system;

            // Create recognizer
            recognizer = new SpeechRecognizer();

            // Configure to never stop listening
            recognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout = TimeSpan.MaxValue;

            // Subscribe to events
            recognizer.StateChanged += RecognizerStateChanged;
            recognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
            recognizer.ContinuousRecognitionSession.ResultGenerated += RecognizerResultGenerated;

            // Load constraint
            var constraint = await LoadDynamicConstraintAsync();

            // Add constraint to recognizer
            recognizer.Constraints.Add(constraint);

            // Compile
            var compileResult = await recognizer.CompileConstraintsAsync();

            Debug.WriteLine("Grammar Compiled: " + compileResult.Status.ToString());

            // We're initialized now
            isInitialized = true;

            // If successful start recognition
            if (compileResult.Status == SpeechRecognitionResultStatus.Success)
            {
                await recognizer.ContinuousRecognitionSession.StartAsync(SpeechContinuousRecognitionMode.Default);
            }

            // Return the result
            return compileResult.Status;
        }
Esempio n. 3
0
        /// <summary>
        /// Loads a minimized data set for design time.
        /// </summary>
        /// <returns>
        /// A minimized <see cref="CelestialSystem"/>.
        /// </returns>
        public CelestialSystem LoadSampleData()
        {
            var sun = new CelestialBody()
            {
                Name = "Sun",
                IoPin = 4,
                Description = "The Sun is the star at the center of the Solar System and is by far the most important source of energy for life on Earth. It is a nearly perfect spherical ball of hot plasma, with internal convective motion that generates a magnetic field via a dynamo process.",
            };

            var earth = new CelestialBody()
            {
                Name = "Earth",
                IoPin = 26,
                Description = "Earth is the third planet from the Sun, the densest planet in the Solar System, the largest of the Solar System's four terrestrial planets, and the only astronomical object known to harbor life.",
                Day = new TimeSpan(24, 0, 0),
                Orbit = 150,
                Year = TimeSpan.FromDays(365)
            };

            var mars = new CelestialBody()
            {
                Name = "Mars",
                Description = "Mars is the fourth planet from the Sun and the second smallest planet in the Solar System, after Mercury. Named after the Roman god of war, it is often referred to as the \"Red Planet\" because the iron oxide prevalent on its surface gives it a reddish appearance.",
                Day = new TimeSpan(24, 39, 0),
                Orbit = 230,
                Year = TimeSpan.FromDays(687)
            };


            var iceFact = new CelestialFact()
            {
                Title = "Planets with ice",
                Contributor = "Bienz / Vasek Family",
                Description = "Both Earth and Mars have ice but Mars contains very little ice.",
                Bodies = new List<CelestialBody>()
                {
                    earth,
                    mars
                }
            };

            var system = new CelestialSystem()
            {
                Bodies = new List<CelestialBody>()
                {
                    sun,
                    earth,
                    mars
                },
                Facts = new List<CelestialFact>()
                {
                    iceFact
                }
            };

            string ssjson = JsonConvert.SerializeObject(system, Formatting.Indented);

            return system;
        }