コード例 #1
0
        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
                    {
                    }
                }
            }
        }
コード例 #2
0
        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
                    {

                    }
                }
            }
        }