当前位置: 首页>>代码示例>>C#>>正文


C# SpeechSynthesizer.SpeakTextAsync方法代码示例

本文整理汇总了C#中SpeechSynthesizer.SpeakTextAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechSynthesizer.SpeakTextAsync方法的具体用法?C# SpeechSynthesizer.SpeakTextAsync怎么用?C# SpeechSynthesizer.SpeakTextAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpeechSynthesizer的用法示例。


在下文中一共展示了SpeechSynthesizer.SpeakTextAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: handleDownloadStringComplete

        private void handleDownloadStringComplete(object sender, DownloadStringCompletedEventArgs e)
        {
            if (Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable)
            {
                XNamespace media = XNamespace.Get("http://search.yahoo.com/mrss/");
                titles = System.Xml.Linq.XElement.Parse(e.Result).Descendants("title")
                    .Where(m => m.Parent.Name == "item")
                    .Select(m => m.Value)
                    .ToArray();

                descriptions = XElement.Parse(e.Result).Descendants("description")
                    .Where(m => m.Parent.Name == "item")
                    .Select(m => m.Value)
                    .ToArray();

                images = XElement.Parse(e.Result).Descendants(media + "thumbnail")
                    .Where(m => m.Parent.Name == "item")
                    .Select(m => m.Attribute("url").Value)
                    .ToArray();

                SpeechSynthesizer synth = new SpeechSynthesizer();
                synth.SpeakTextAsync(titles[0]).Completed += new AsyncActionCompletedHandler(delegate(IAsyncAction action, AsyncStatus status)
                    {
                        synth.SpeakTextAsync(descriptions[0]);
                    });
                UpdatePrimaryTile(titles[0], images[0]);

            }
            else
            {
                MessageBox.Show("No network is available...");
            }
        }
开发者ID:king-dev,项目名称:WP8_RssNewsReader,代码行数:33,代码来源:MainPage.xaml.cs

示例2: ReadAloud_Click

        private void ReadAloud_Click(object sender, RoutedEventArgs e)
        {
            var sync = new SpeechSynthesizer();

            // auf Ende des Vorlesevorganges wird nicht gewartet
            sync.SpeakTextAsync(TextToRead.Text);
        }
开发者ID:GregOnNet,项目名称:WP8BookSamples,代码行数:7,代码来源:TextToSpeechPage.xaml.cs

示例3: Speak

        private async void Speak()
        {
            SpeechSynthesizer ss = new SpeechSynthesizer();
            VoiceInformation vi = InstalledVoices.All.Where(v => v.Language == "en-EN" && v.Gender == VoiceGender.Male).FirstOrDefault();
            ss.SetVoice(vi);
            int rand=(int)RandomService.Instance.getRand(0, 3);
            string answer="";
            switch (rand)
            {
                case 0:
                    answer = "yes";
                    break;
                case 1:
                    answer = "no";
                    break;
                case 2:
                    answer = "maybe";
                    break;
                case 3:
                    answer = "I don't know";
                    break;

            }
            AnswerText.Text = answer;
            await ss.SpeakTextAsync(answer);
        }
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:26,代码来源:MainPage.xaml.cs

示例4: SpeakClick

        private async void SpeakClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(inputTextBox.Text))
                MessageBox.Show("Introduce algun texto a leer.");
            else
            {
                try
                {
                    SpeechSynthesizer synth = new SpeechSynthesizer();

                    var voices = InstalledVoices.All.Where(v => v.Language == "es-ES").OrderByDescending(v => v.Gender);

                    VoiceGender gender = VoiceGender.Male;

                    if (rbMale.IsChecked == true)
                        gender = VoiceGender.Male;
                    else
                        gender = VoiceGender.Female;

                    synth.SetVoice(voices.Where(v => v.Gender == gender).FirstOrDefault());

                    await synth.SpeakTextAsync(inputTextBox.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
开发者ID:rwecho,项目名称:Windows-Phone-Samples,代码行数:29,代码来源:MainPage.xaml.cs

示例5: Speak

        public static async Task Speak(string text)
        {
            ExceptionDispatchInfo capturedException = null;

            using (var speech = new SpeechSynthesizer())
            {
                try
                {
                    await speech.SpeakTextAsync(text);
                }
                catch (Exception ex)
                {

                    capturedException = ExceptionDispatchInfo.Capture(ex);
                }

                if (capturedException != null)
                {
                    MessageBox.Show(capturedException.SourceException.Message);

                    //capturedException.Throw();
                }


            }

        }
开发者ID:dfwdino,项目名称:Freddys-Phone-AppV1,代码行数:27,代码来源:TextToSpeech.xaml.cs

示例6: btnSearch_Click

        private async void btnSearch_Click(object sender, EventArgs e)
        {
            App.speechRecognizerWithUI.Settings.ExampleText = "salad";
            App.speechRecognizerWithUI.Settings.ShowConfirmation = true;
            App.speechRecognizerWithUI.Settings.ListenText = "What are you looking for?";
            var result = await App.speechRecognizerWithUI.RecognizeWithUIAsync();

            if (result.ResultStatus == Windows.Phone.Speech.Recognition.SpeechRecognitionUIStatus.Succeeded)
            {
                SpeechSynthesizer synth = new SpeechSynthesizer();

                if (result.RecognitionResult.TextConfidence == Windows.Phone.Speech.Recognition.SpeechRecognitionConfidence.High ||
                    result.RecognitionResult.TextConfidence == Windows.Phone.Speech.Recognition.SpeechRecognitionConfidence.Medium)
                {
                    var recipe = App.Recipes.FindRecipeByText(result.RecognitionResult.Text);

                    if (null != recipe)
                        NavigationService.Navigate(new Uri("/RecipeDetailPage.xaml?ID=" + recipe.UniqueId, UriKind.Relative));
                    else
                        await synth.SpeakTextAsync(string.Format("Cannot find any {0}. I am sorry!"), result.RecognitionResult.Text);
                }
                else
                {
                    await synth.SpeakTextAsync("I am not sure what you just said. Please try again!");
                }
            }
        }
开发者ID:WindowsPhone-8-TrainingKit,项目名称:HOL-VoiceCommands,代码行数:27,代码来源:MainPage.xaml.cs

示例7: SpeakNotifications

        private async void SpeakNotifications()
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            StringBuilder sb = new StringBuilder();

            if (Tweets.Count == 0)
            {
                await synth.SpeakTextAsync(Resources.NoNewNotifications);
                return;
            }

            foreach (var tweet in Tweets)
                sb.AppendLine(TweetToText(tweet));

            await synth.SpeakTextAsync(sb.ToString());
        }
开发者ID:rafaelwinter,项目名称:Ocell,代码行数:16,代码来源:NotificationsModel.cs

示例8: SelectSynthVoice

 private async void SelectSynthVoice(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (e.AddedItems != null && e.AddedItems.Count != 0)
     {
         _speechSynth = new SpeechSynthesizer();
         _speechSynth.SetVoice((VoiceInformation)e.AddedItems[0]);
         await _speechSynth.SpeakTextAsync(TextToSpeechBox.Text);
     }
 }
开发者ID:WindowsPhone-8-TrainingKit,项目名称:PRESENTATION-Sensors,代码行数:9,代码来源:SpeechDemo.xaml.cs

示例9: Leer_Click

        private void Leer_Click(object sender, RoutedEventArgs e)
        {
            var synth = new SpeechSynthesizer();

            var voices = InstalledVoices.All.Where(v => v.Language == "es-ES").OrderByDescending(v => v.Gender);

            synth.SetVoice(voices.FirstOrDefault(v => v.Gender == VoiceGender.Male));

            _task = synth.SpeakTextAsync("Esto es una prueba. Realmente dura mucho más de lo necesario. Si quieres puedes parar pulsando el botón Parar Voz");
        }
开发者ID:rwecho,项目名称:Windows-Phone-Samples,代码行数:10,代码来源:MainPage.xaml.cs

示例10: ReadAloudWithOptions_Click

        private async void ReadAloudWithOptions_Click(object sender, RoutedEventArgs e)
        {
            var sync = new SpeechSynthesizer();

            // als Sprache eine männliche, deutsche Stimme von den installierten Sprachen abrufen und setzen
            var voice = InstalledVoices.All.FirstOrDefault(v => v.Language == "de-DE" && v.Gender == VoiceGender.Male);
            sync.SetVoice(voice);

            // auf Ende des Vorlesevorganges warten
            await sync.SpeakTextAsync(TextToRead.Text);
        }
开发者ID:GregOnNet,项目名称:WP8BookSamples,代码行数:11,代码来源:TextToSpeechPage.xaml.cs

示例11: let_sSpeak

        /*//*/
        /// <summary>
        /// When the user clicks on the button "let_sRead", the device reads the content of "text_read".
        /// </summary>
        /// <param name="sender">Don't know!</param>
        /// <param name="e">Don't know!</param>
        private async void let_sSpeak(/*object sender, RoutedEventArgs e*/) 
        {
            if (toSay != null || toSay != "")
            {
                SpeechSynthesizer synth = new SpeechSynthesizer();

                await synth.SpeakTextAsync(toSay);

            }

        }
开发者ID:symsymmas,项目名称:MyFirstApp_voiceSynthesizer,代码行数:17,代码来源:MainPage.xaml.cs

示例12: Speak

        /// <summary>
        /// 
        /// </summary>
        /// <param name="text"></param>
        public async void Speak(string text)
        {
            var voices = from v in InstalledVoices.All
                         where v.Language == MainPage.lanEn
                         select v;

            var speech = new SpeechSynthesizer();
            speech.SetVoice(voices.ElementAt(0));

            await speech.SpeakTextAsync(text);
        }
开发者ID:juano31,项目名称:Tareas,代码行数:15,代码来源:MainPage.xaml.cs

示例13: ReadOutLoud

        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
                    {

                    }
                }
            }
        }
开发者ID:Hitchhikrr,项目名称:Hackathon,代码行数:53,代码来源:ContentDisplayPage.xaml.cs

示例14: Say

        public async Task Say(string text, string filterLanguage = null)
        {
            // Query for a voice that speaks French.
            filterLanguage = filterLanguage ?? Languages.esES;
            IEnumerable<VoiceInformation> voices = from voice in InstalledVoices.All
                                                   where voice.Language == filterLanguage
                                                   select voice;

            // Set the voice as identified by the query.
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SetVoice(voices.ElementAt(0));
            await synth.SpeakTextAsync(text);

        }
开发者ID:hmadrigal,项目名称:playground-csharp-windowsphone8,代码行数:14,代码来源:SpeechHelper.cs

示例15: TextToSpeech

        public async void TextToSpeech(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                var synth = new SpeechSynthesizer();

                IOrderedEnumerable<VoiceInformation> voices =
                    InstalledVoices.All.Where(v => v.Language == "es-ES").OrderByDescending(v => v.Gender);

                const VoiceGender gender = VoiceGender.Female;

                synth.SetVoice(voices.FirstOrDefault(v => v.Gender == gender));

                await synth.SpeakTextAsync(text);
            }
        }
开发者ID:JavierErdozain,项目名称:Events,代码行数:16,代码来源:SpeechService.cs


注:本文中的SpeechSynthesizer.SpeakTextAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。