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


C# SpeechSynthesizer.SetVoice方法代码示例

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


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

示例1: 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

示例2: 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

示例3: CreateSpeech

 static private SpeechSynthesizer CreateSpeech()
 {
     var speech = new SpeechSynthesizer();
     var language = CultureInfo.CurrentCulture.ToString();
     var voices = InstalledVoices.All.Where(v => v.Language == language).OrderByDescending(v => v.Gender);
     speech.SetVoice(voices.FirstOrDefault(v => v.Gender == gender));
     return speech;
 }
开发者ID:Belenar,项目名称:OtherAppRepository,代码行数:8,代码来源:SpeechServices.cs

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: GetSpeechSynthesizer

        private static SpeechSynthesizer GetSpeechSynthesizer()
        {
            var speechSynthesizer = new SpeechSynthesizer();

            IEnumerable<VoiceInformation> enUSMaleVoices = from voice in InstalledVoices.All
                                                           where voice.Gender == VoiceGender.Male &&
                                                                 voice.Language == "en-US"
                                                           select voice;

            speechSynthesizer.SetVoice(enUSMaleVoices.ElementAt(0));
            return speechSynthesizer;
        }
开发者ID:richhildebrand,项目名称:TimerApp_WP8,代码行数:12,代码来源:Speech.cs

示例10: 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

示例11: 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

示例12: PhrasesManager

        public PhrasesManager()
        {
            PhraseEngine.PhraseInitilaze();
            try
            {
                synth = new SpeechSynthesizer();
                VoiceInformation voices = InstalledVoices
                    .All
                    .Where(x => x.Language == "en-US")
                    .FirstOrDefault();
                if (voices != null)
                    synth.SetVoice(voices);
                _phraseAutomat = new PhraseAutomat();
            }
            catch(Exception ex)
            {

            }
        }
开发者ID:Malanin,项目名称:EnglishWithFriends,代码行数:19,代码来源:PhrasesManager.cs

示例13: WordsManager

        public WordsManager()
        {
            WordEngine.WordInitilaze();
            try
            {
                synth = new SpeechSynthesizer();
                VoiceInformation voices = InstalledVoices
                    .All
                    .Where(x => x.Language == "en-US")
                    .FirstOrDefault();
                if (voices != null)
                    synth.SetVoice(voices);
                _wordAutomat = new WordAutomat();
            }
            catch(Exception e)
            {

            }
        }
开发者ID:Malanin,项目名称:EnglishWithFriends,代码行数:19,代码来源:WordsManager.cs

示例14: TextToSpeech

        /// <summary>
        /// Converts a text into a speech and pronounces it.
        /// </summary>
        /// <param name="text">The text to be pronounced.</param>
        public async void TextToSpeech(string text)
        {
            try
            {
                if (!string.IsNullOrEmpty(text))
                {
                    var synth = new SpeechSynthesizer();

                    var language = CultureInfo.CurrentCulture.ToString();

                    var voices = InstalledVoices.All.Where(v => v.Language == language).OrderByDescending(v => v.Gender);

                    const VoiceGender gender = VoiceGender.Female;

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

                    await synth.SpeakTextAsync(HtmlUtil.CleanHtml(text));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("{0}{1}. {2}{3}", AppResources.SpeechError, text, AppResources.Error, ex.ToString());
            }
        }
开发者ID:violabazanye,项目名称:CinemaTalk,代码行数:28,代码来源:SpeechService.cs

示例15: Listen

        private async void Listen()
        {
            if (!busy)
            {
                busy = true;
                // Initialize the SpeechRecognizerUI object.
                recoWithUI = new SpeechRecognizerUI();

                // Query for a recognizer that recognizes French as spoken in France.
                IEnumerable<SpeechRecognizerInformation> recognizers = from recognizerInfo in InstalledSpeechRecognizers.All
                                                                       select recognizerInfo;

                // Set the recognizer to the top entry in the query result.
                recoWithUI.Recognizer.SetRecognizer(recognizers.ElementAt(0));

                // Create a string array of French numbers.
                string[] settings = (from MarketCat cat in listOfCats.ToList()
                                     select cat.Title).ToArray();

                // Create a list grammar from the string array and add it to the grammar set.
                recoWithUI.Recognizer.Grammars.AddGrammarFromList("categories", settings);

                string listenText = "";
                string exampleText = "";
                for (int i = 0; i < settings.Length; i++)
                {
                    listenText += settings[i];
                    exampleText += " " + settings[i];
                }
                // Display text to prompt the user's input.
                recoWithUI.Settings.ListenText = "Category Between: ";

                recoWithUI.Settings.ReadoutEnabled = false;
                // Give an example of ideal speech input.
                recoWithUI.Settings.ExampleText = exampleText;

                // Load the grammar set and start recognition.
                SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
                string action = recoResult.RecognitionResult.Text;
                SpeechSynthesizer ss = new SpeechSynthesizer();
                VoiceInformation vi = InstalledVoices.All.Where(v => v.Language == "en-EN" && v.Gender == VoiceGender.Male).FirstOrDefault();
                ss.SetVoice(vi);
                await ss.SpeakTextAsync("I'm looking for " + action + "!");
                MarketCat chooseCat = (from MarketCat cat in listOfCats.ToList()
                                       where cat.Title == action
                                       select cat).FirstOrDefault();
                chooseAppsPreview = CreateAppsPreview(chooseCat);
                CategorieTitle.Text = chooseCat.Title;
                AppsPreviewContent.Children.Clear();
                AppsPreviewContent.Children.Add(chooseAppsPreview);
                chooseAppsPreview.load();

                chooseAppsPreview.CompletedEvent+= (e, o) =>
                {
                    sayAppName();
                };
               
            }
            busy = false;
        }
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:60,代码来源:MainPage.xaml.cs


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