예제 #1
0
        static bool isLocalRssFeed = true;  //the flow for isLocalRssFeed = false is not yet supported

        public static void ReadNewsByCategory(string cat)
        {
            RssParser rssParser = new RssParser();
            string feedFileName = GetRssFeedFileNameByCategory(cat);
            if (isLocalRssFeed)
                rssParser.initializeLocal(feedFileName);
            else
                rssParser.initialize("https://www.bing.com/news/?format=RSS");

            ReadOutLoud(GetNewsSummary(rssParser));
        }
        public async void ReadOutLoud()
        {
            IEnumerable<VoiceInformation> voices = from voice in InstalledVoices.All
                                                   where voice.Language == "en-US" && voice.Gender == VoiceGender.Female
                                                   select voice;

            // Set the voice as identified by the query.
            //try
            //{
            //    if(voices.Count() > 0)
            //        synth.SetVoice(voices.ElementAt(0));
            //}
            //catch
            //{

            //}

            ICategoryRepository categoryRepository = new XmlCategoryRepository();

            foreach (string id in categoryIds)
            {
                CategoryData category = categoryRepository.GetCategoryById(Convert.ToInt32(id));
                //this.CategoryName.Text = category.Name;
                Uri imageUri = new Uri(category.Image, UriKind.Relative);
                var bitmap = new BitmapImage(imageUri);
                this.CategoryImage.Source = bitmap;
                RssParser rssParser = new RssParser();
                Uri feedUri = new Uri(category.Feed, UriKind.Relative);
                StreamResourceInfo sri = Application.GetResourceStream(feedUri);
                rssParser.initializeLocal(sri.Stream);
                List<NewsItem> topStories = rssParser.getTopStories();
                foreach (NewsItem newsItem in topStories)
                {
                    try
                    {
                        synth = new SpeechSynthesizer();
                        if (voices.Count() > 0)
                            synth.SetVoice(voices.ElementAt(0));
                        if (String.IsNullOrEmpty(newsItem.description))
                            continue;
                        this.CategoryName.Text = newsItem.title;
                        this.SummaryBlock.Text = newsItem.description;
                        string textToRead = newsItem.title + ".\n" + newsItem.source + " reports, " + newsItem.description + "\n\n";
                        await synth.SpeakTextAsync(textToRead);
                        synth.Dispose();
                    }
                    catch
                    {

                    }
                }
            }
        }
예제 #3
0
        public static List<NewsSummary> GetNewsSummary(RssParser rssParser)
        {
            List<NewsSummary> ListOfSummaries = new List<NewsSummary>();

            List<NewsItem>  topStories = rssParser.getTopStories(2);
            foreach (NewsItem newsItem in topStories)
            {
                ListOfSummaries.Add(new NewsSummary(newsItem.url));
            }
            
            return ListOfSummaries;
        }