예제 #1
0
        private void SpeakWeather(WeatherModel weatherModel)
        {
            var weather = new StringBuilder();

            weather.AppendLine("I see " + weatherModel.Description);
            weather.AppendLine("It feels like " + weatherModel.FeelsLike + " degree celsius.");
            weather.AppendLine("and Humidity is " + weatherModel.Humidity);

            var weatherSpeechThread = new Thread(new ThreadStart(() => m_speechContext.Speak(weather.ToString())));

            weatherSpeechThread.IsBackground = true;
            weatherSpeechThread.Start();
        }
예제 #2
0
        private void GetWeather()
        {
            if (!m_weatherDataCached)
            {
                MakeWeatherRequest();
            }

            var currentWeather = new WeatherModel()
            {
                Time        = (string)m_weatherResponseObject["current"]["dt"],
                FeelsLike   = (string)m_weatherResponseObject["current"]["feels_like"],
                Humidity    = (string)m_weatherResponseObject["current"]["humidity"],
                WindSpeed   = (string)m_weatherResponseObject["current"]["wind_speed"],
                Description = (string)m_weatherResponseObject["current"]["weather"][0]["description"],
                Sunset      = (string)m_weatherResponseObject["current"]["sunset"],
                Sunrise     = (string)m_weatherResponseObject["current"]["sunrise"]
            };

            SpeakWeather(currentWeather);
        }
예제 #3
0
        private void GetForecast()
        {
            if (!m_weatherDataCached)
            {
                MakeWeatherRequest();
            }

            var hourlyWeatherData  = (JArray)m_weatherResponseObject["hourly"];
            var hourlyWeatherModel = new List <WeatherModel>();

            foreach (var hourlyData in hourlyWeatherData)
            {
                var hourlyWeather = new WeatherModel()
                {
                    Time        = (string)hourlyData["dt"],
                    FeelsLike   = (string)hourlyData["feels_like"],
                    Humidity    = (string)hourlyData["humidity"],
                    WindSpeed   = (string)hourlyData["wind_speed"],
                    Description = (string)hourlyData["weather"][0]["description"],
                    Sunset      = null,
                    Sunrise     = null
                };
                hourlyWeatherModel.Add(hourlyWeather);
            }

            if (hourlyWeatherModel.Count > 0)
            {
                var forecastModel = hourlyWeatherModel[hourlyWeatherModel.Count / 2];
                if (null != forecastModel)
                {
                    SpeakWeather(forecastModel);
                }
            }
            else
            {
                m_speechContext.Speak("Weather data not found");
            }
        }