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


C# SpeechSynthesizer.SelectVoice方法代码示例

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


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

示例1: SpeechToWavBytes

        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="speechText"></param>
        /// <returns></returns>
        public byte[] SpeechToWavBytes(string speechText)
        {
            if(speechText == null) throw new ArgumentNullException("speechText");
            byte[] result = new byte[] {};

            if(IsSupported) {
                using(MemoryStream memoryStream = new MemoryStream()) {
                    using(SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer() { Rate = -3 }) {
                        var configuration = Factory.Singleton.Resolve<IConfigurationStorage>().Singleton.Load();

                        speechSynthesizer.Rate = configuration.AudioSettings.VoiceRate;
                        string defaultVoice = speechSynthesizer.Voice.Name;
                        try {
                            speechSynthesizer.SelectVoice(configuration.AudioSettings.VoiceName);
                        } catch(Exception ex) {
                            Debug.WriteLine(String.Format("Audio.SpeechToWavBytes caught exception {0}", ex.ToString()));
                            speechSynthesizer.SelectVoice(defaultVoice);
                        }

                        speechSynthesizer.SetOutputToWaveStream(memoryStream);
                        speechSynthesizer.Speak(speechText);
                    }

                    memoryStream.Flush();
                    result = memoryStream.ToArray();
                }
            }

            return result;
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:35,代码来源:Audio.cs

示例2: Speaker

        public Speaker(Language lang = Language.English)
        {
            this.lang = lang;
            AsyncMode = false;  // Default to synchron speech
            UseSSML = false;	// Default to non-SSML speech

            try
            {
                // Create synthesizer
                ss = new SpeechSynthesizer();
                ss.SetOutputToDefaultAudioDevice();

                // Select language
                if (!UseSSML)
                {
                    switch (lang)
                    {
                        case Language.English: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-GB, Hazel)"); break;
                        case Language.Finish: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (fi-FI, Heidi)"); break;
                        case Language.Norwegian: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (nb-NO, Hulda)"); break;
                        case Language.Russian: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (ru-RU, Elena)"); break;
                        case Language.Swedish: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (sv-SE, Hedvig)"); break;
                        default: ss.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-GB, Hazel)"); break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: '{0}'", e);
            }
        }
开发者ID:TommyAGK,项目名称:Flex,代码行数:31,代码来源:Speaker.cs

示例3: initVoice

 /// <summary>
 /// Initiate the SpeechSynthesizer.
 /// </summary>
 /// <returns></returns>
 public static SpeechSynthesizer initVoice()
 {
     synth = new SpeechSynthesizer();
     synth.SetOutputToDefaultAudioDevice();
     synth.SelectVoice(voiceName);
     return synth;
 }
开发者ID:huclepi,项目名称:PCH-Recognition,代码行数:11,代码来源:Voice.cs

示例4: SpeakService

        private SpeakService()
        {
            _synthesizer = new SpeechSynthesizer();
            _synthesizer.SelectVoice(VoiceName);

            Repeat = true;
        }
开发者ID:dalinhuang,项目名称:appcollection,代码行数:7,代码来源:SpeakService.cs

示例5: SpeechSynchrone

 // Méthode permettant de lancer la synchronisation de maniere synchrone
 //
 public static void SpeechSynchrone(String text)
 {
     SpeechSynthesizer s = new SpeechSynthesizer();
     String voix = "ScanSoft Virginie_Dri40_16kHz";
     s.SelectVoice(voix);
     s.Speak(text);
 }
开发者ID:FabienInspiron,项目名称:ProjetDevintInspiron,代码行数:9,代码来源:Voice.cs

示例6: VoiceCanBeHeard

        public void VoiceCanBeHeard() {
            var synth = new SpeechSynthesizer();
            synth.SelectVoice("Microsoft Hazel Desktop");
            synth.Speak("This is an example of what to do");
            synth.Speak(NumberUtilities.Direction.Ascending.ToString());

        }
开发者ID:aadennis,项目名称:TonesApp,代码行数:7,代码来源:IntervalSpeechTests.cs

示例7: ConfigureVoice

 public static bool ConfigureVoice(SpeechSynthesizer synth, string name, int speed, int volume, bool defaultOutput, int customOutput)
 {
     try
     {
         synth.SetOutputToDefaultAudioDevice();
         if (!defaultOutput)
         {
             HackCustomDevice(synth, customOutput);
             // do stuff.
         }
     }
     catch
     {
     }
     if (string.IsNullOrEmpty(name))
         name = initialName;
     try
     {
         if (!string.IsNullOrEmpty(name))
             synth.SelectVoice(name);
     }
     catch
     {
         return false;
     }
     synth.Rate = speed;
     synth.Volume = volume;
     return true;
 }
开发者ID:Tilps,项目名称:Stash,代码行数:29,代码来源:ChatSettingsForm.cs

示例8: load_listen

        public void load_listen(VI_Profile profile, VI_Settings settings, ListView statusContainer)
        {
            this.profile = profile;
            this.settings = settings;
            this.statusContainer = statusContainer;

            vi_syn = profile.synth;
            vi_syn.SelectVoice(settings.voice_info);
            vi_sre = new SpeechRecognitionEngine(settings.recognizer_info);

            GrammarBuilder phrases_grammar = new GrammarBuilder();
            List<string> glossory = new List<string>();

            foreach (VI_Phrase trigger in profile.Profile_Triggers)
            {
                glossory.Add(trigger.value);
            }
            if (glossory.Count == 0)
            {
                MessageBox.Show("You need to add at least one Trigger");
                return;
            }
            phrases_grammar.Append(new Choices(glossory.ToArray()));

            vi_sre.LoadGrammar(new Grammar(phrases_grammar));
            //set event function
            vi_sre.SpeechRecognized += phraseRecognized;
            vi_sre.SpeechRecognitionRejected += _recognizer_SpeechRecognitionRejected;
            vi_sre.SetInputToDefaultAudioDevice();
            vi_sre.RecognizeAsync(RecognizeMode.Multiple);
        }
开发者ID:jjonj,项目名称:AVPI,代码行数:31,代码来源:VI.cs

示例9: Main

        static void Main(string[] args)
        {
            string voiceFileName = args[0];
            string voiceFileNamemp3 = voiceFileName.Replace(".wav", ".mp3");
            string voiceFilePath = args[1];
            string toBeVoiced = args[2];
            int rate = int.Parse(args[3]); ;
            string voice = args[4];

            voiceFileName = voiceFileName.Replace("~", " ");
            voiceFilePath = voiceFilePath.Replace("~", " ");
            toBeVoiced = toBeVoiced.Replace("~", " ");
            voice = voice.Replace("~", " ");

            var reader = new SpeechSynthesizer();
            reader.Rate = rate;
            reader.SelectVoice(voice);

            try
            {
                reader.SetOutputToWaveFile(voiceFilePath + voiceFileName, new SpeechAudioFormatInfo(16025, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
                reader.Speak(toBeVoiced);
                reader.Dispose();
                WaveToMP3(voiceFilePath + voiceFileName, voiceFilePath + voiceFileNamemp3);
            }
            catch (Exception er)
            {
                string s1 = er.Message;
            }
        }
开发者ID:connecticutortho,项目名称:ct-ortho-repositories4,代码行数:30,代码来源:Program.cs

示例10: TestButton_Click

 private void TestButton_Click(object sender, EventArgs e)
 {
     SpeechSynthesizer synth = new SpeechSynthesizer();
     synth.SelectVoice(_settings.CurrentTTSVoice.VoiceInfo.Name);
     synth.Rate = _settings.TTS_Rate;
     synth.SpeakAsync("This is " + _settings.CurrentTTSVoice.VoiceInfo.Description + " Speaking at a rate of " + _settings.TTS_Rate);
 }
开发者ID:sorvis,项目名称:Fast-Script,代码行数:7,代码来源:To_MP3_Options.cs

示例11: Run

 public void Run()
 {
     using (SpeechSynthesizer speaker = new SpeechSynthesizer()) {
         speaker.SelectVoice(VoiceName);
         speaker.Rate = Rate;
         speaker.Speak(Text);
     }
 }
开发者ID:infl3x,项目名称:Say-shit-on-my-computer,代码行数:8,代码来源:SpeechTask.cs

示例12: AIModule

 public AIModule()
 {
     iTunes = new iTunesLib.iTunesApp();
     bot = new SpeechSynthesizer();
     bot.SelectVoice("VW Paul");
     bot.Rate = 1;
     bot.Volume = 100;
 }
开发者ID:andrewxu,项目名称:ProjectXenix,代码行数:8,代码来源:AIModule.cs

示例13: Speech

 public Speech()
 {
     sr = new SpeechRecognitionEngine();
     ss = new SpeechSynthesizer();
     sr.SetInputToDefaultAudioDevice();
     ss.SelectVoice("Microsoft Anna");
     ss.SetOutputToDefaultAudioDevice();
 }
开发者ID:nbotti,项目名称:Assistant,代码行数:8,代码来源:Speech.cs

示例14: Play

 public void Play()
 {
     speaker = new SpeechSynthesizer();
     speaker.SelectVoice("ScanSoft Raquel_Full_22kHz");
     speaker.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(speaker_SpeakCompleted);
     speaker.SpeakAsync(texto);
     speaker.Resume();
 }
开发者ID:vanderleiarruda,项目名称:aturtes,代码行数:8,代码来源:BFala.cs

示例15: Speak

        public string Speak(string sText, bool bToFile)
        {
            SpeechSynthesizer oSpeaker = new SpeechSynthesizer();

            oSpeaker.Rate = 1;
            oSpeaker.SelectVoice("Microsoft Anna");

            oSpeaker.Volume = 100;

            if (bToFile)
            {
                oSpeaker.SetOutputToWaveFile("SoundByte.wav");
            }
            oSpeaker.Speak(sText);

            string msg;
            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                // Get information about supported audio formats.
                string AudioFormats = "";
                foreach (SpeechAudioFormatInfo fmt in synth.Voice.SupportedAudioFormats)
                {
                    AudioFormats += String.Format("{0}\n",
                    fmt.EncodingFormat.ToString());
                }

                // Write information about the voice to the console.
                msg = "Name:          " + synth.Voice.Name + "\n";
                msg += "Culture:       " + synth.Voice.Culture + "\n";
                msg += " Age:           " + synth.Voice.Age + "\n";
                msg += " Gender:        " + synth.Voice.Gender + "\n";
                msg += " Description:   " + synth.Voice.Description + "\n";
                msg += " ID:            " + synth.Voice.Id + "\n";
                if (synth.Voice.SupportedAudioFormats.Count != 0)
                {
                     msg += " Audio formats: " + AudioFormats + "\n";
                }
                else
                {
                     msg += " No supported audio formats found" + "\n";
                }

                // Get additional information about the voice.

                foreach (string key in synth.Voice.AdditionalInfo.Keys)
                {
                    msg += String.Format("  {0}: {1}\n",key, synth.Voice.AdditionalInfo[key]);
                }

                msg += " Additional Info - ";

            }
            oSpeaker.Dispose();
            oSpeaker = null;
            return msg;
        }
开发者ID:bfoote,项目名称:StudentInformation,代码行数:58,代码来源:CPerson.cs


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