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


C# SpeechSynthesizer.Speak方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            string sURL;
            sURL = "http://api.nytimes.com/svc/topstories/v1/yourAPIKey";
            WebRequest wrGETURL;
            wrGETURL = WebRequest.Create(sURL);
            wrGETURL.Proxy = WebProxy.GetDefaultProxy();
            Stream objStream;
            objStream = wrGETURL.GetResponse().GetResponseStream();
            StreamReader objReader = new StreamReader(objStream);
            string line = "";
            line = objReader.ReadLine();
            line = line.Replace("\"abstract\"","\"abstra\"");
            dynamic stories = JsonConvert.DeserializeObject<Rootobject>(line);
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                // Configure the audio output.
                synth.SetOutputToDefaultAudioDevice();
                for (int i = 0; i < stories.num_results; i++)
                {
                    // Speak a string synchronously.
                    string number = i.ToString();
                    synth.Speak(number+ "\n" + stories.results[i].title);
                    synth.Speak(stories.results[i].abstra);
                }
            }
        }
开发者ID:ycen,项目名称:TimeSpeak,代码行数:28,代码来源:Program.cs

示例2: OpenPullRequestMonitor

        public OpenPullRequestMonitor(TimeSpan timespan, ItemState state=ItemState.Open)
        {
            var pollingPeriod = timespan.TotalMilliseconds;
            _timer = new Timer(pollingPeriod) {AutoReset = true};
            _timer.Elapsed += (sender, eventArgs) =>
            {
                var prs = 0;
                Task.Run(async () =>
                {
                    var requests = await PollGitHub(state);
                    prs = requests.Count;
                    _pr = requests.FirstOrDefault();
                    Console.WriteLine("Polled PR count:" + prs);
                }).Wait();

                if (prs > OpenPrs)
                {
                    var soundPlayer = new SoundPlayer("fanfare3.wav");
                    soundPlayer.PlaySync();
                    if (_pr != null)
                    {
                        var speech = new SpeechSynthesizer();
                        speech.Speak("New pull request.");
                        speech.Speak(_pr.Title);
                    }

                    OpenPrs = prs;
                }
                else if (prs < OpenPrs)
                {
                    OpenPrs = prs;
                }
            };
        }
开发者ID:awcoats,项目名称:PRNotifier,代码行数:34,代码来源:OpenPullRequestMonitor.cs

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

示例4: Test

 public static void Test()
 {
     SpeechSynthesizer synth = new SpeechSynthesizer();
     PromptBuilder pb = new PromptBuilder();
     pb.AppendText("Welcome, everyone");
     synth.Speak(pb);
 }
开发者ID:praveenv4k,项目名称:indriya,代码行数:7,代码来源:SpeechSynthesis.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: Main

        static void Main()
        {

            IList<string> args = new List<string>();
            string s = Console.ReadLine();
            while(!string.IsNullOrEmpty(s)){
                args.Add(s);
                s = Console.ReadLine();
            }

            foreach (string word in args)
            //Create wav file for each sound
            {
                using (FileStream f = new FileStream(word + ".wav", FileMode.Create))
                {
                    using (SpeechSynthesizer speak = new SpeechSynthesizer())
                    {
                        speak.SetOutputToWaveStream(f);
                        speak.Speak(word);
                    }
                }
                //Create phoneme text file for each word                
                using (FileStream f = new FileStream(word + ".txt", FileMode.Create))
                {
                    //call function to extract the phoneme
                    ExtractPhoneme2 extract = new ExtractPhoneme2();
                    string phoneme = extract.getPhoneme(word);

                    //Encode the phoneme and write  to file
                    Byte[] info = new UTF8Encoding(true).GetBytes(phoneme + "\n");                    
                    f.Write(info, 0, info.Length);
                }
            }
        }
开发者ID:alulam,项目名称:NaturalSpeech,代码行数:34,代码来源:Program.cs

示例7: Main

        static void Main(string[] args)
        {
            SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
            speechSynthesizer.Speak("Welcome to the speaking performance monitor!");

            #region Performance Counters
            PerformanceCounter performanceCounter_CPU = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
            PerformanceCounter performanceCounter_RAM = new PerformanceCounter("Memory", "% Committed Bytes In Use");
            PerformanceCounter performanceCounter_TIME = new PerformanceCounter("System", "System Up Time"); 
            #endregion

            while (true)
            {
                float currentCPUPercentage = performanceCounter_CPU.NextValue();
                float currentRAMPercentage = performanceCounter_RAM.NextValue();

                Console.WriteLine("CPU Load:  {0}%", currentCPUPercentage);
                Console.WriteLine("RAM Usage: {0}%", currentRAMPercentage);

                string cpuLoadVocalMessage = String.Format("The current CPU load  is: {0}", currentCPUPercentage);
                string ramLoadVocalMessage = String.Format("The current RAM usage is: {0}", currentRAMPercentage);

                Thread.Sleep(500);
            }
        }
开发者ID:BjornNorgaard,项目名称:Random-Projects,代码行数:25,代码来源:Program.cs

示例8: TryInvokeMember

 public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
 {
     SpeechSynthesizer ss = new SpeechSynthesizer();
     ss.Speak(binder.Name);
     result = true;
     return true;
 }
开发者ID:Laubeee,项目名称:ecnf,代码行数:7,代码来源:Speech.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: 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

示例11: Main

        // Where all the magic happens
        static void Main(string[] args)
        {
            // This greets the user in the default voice
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.Speak("Welcome to Petko Trenev's program");

            #region My Performance Counters
            // This will pull the current CPU load in percentage
            PerformanceCounter perfCpuCount = new PerformanceCounter("Processor information", "% Processor Time", "_Total");

            // This will pull the available memory in MB
            PerformanceCounter perfMemoryCounter = new PerformanceCounter("Memory", "Available MBytes");

            // Number of time the system has been on (in seconds)
            PerformanceCounter perfUpTimeCount = new PerformanceCounter("System", "System Up Time");
            #endregion

            // Infinite while loop
            while (true)
            {
                int currentCpuPercentage =(int) perfCpuCount.NextValue();
                int currentAvailableMemory =(int) perfMemoryCounter.NextValue();

                // Every one second print the CPU load in percentage on screen
                Console.WriteLine("CPU load is      : {0}%",currentCpuPercentage);
                Console.WriteLine("Available Memory : {0}GB",currentAvailableMemory);

                // Only speak to me if the percentages are more than 80 percent
                if (currentCpuPercentage > 80)
                {
                    string cpuLoadVocalMessage = String.Format("The current CPU load is : {0} percent", currentCpuPercentage);
                    synth.Speak(cpuLoadVocalMessage);
                }

                // Only speak to me if the memory is bellow 1024
                if (currentAvailableMemory < 1024)
                {
                    string memAvailableVocalMessage = String.Format("The current Available memory is {0} ", currentAvailableMemory);
                    synth.Speak(memAvailableVocalMessage);
                }

                // Speak to the user with text to speech to tell what the current values are

                Thread.Sleep(1000);

            }
        }
开发者ID:PetkoTrenev,项目名称:CSharp-Basics,代码行数:48,代码来源:MyCpuMonitor.cs

示例12: Speakthread

 private void Speakthread(object text)
 {
     SpeechSynthesizer speaker = new SpeechSynthesizer();
     speaker.Rate = -3;
     speaker.Volume = 100;
     speaker.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Child);
     speaker.Speak((string)text);
 }
开发者ID:AtVirus,项目名称:DarkAgent,代码行数:8,代码来源:Talker.cs

示例13: getOutput

 public String getOutput(String rawInput)
 {
     SpeechSynthesizer SpeechSynth = new SpeechSynthesizer();
     Request request = new Request(rawInput, myUser, myBot);
     Result result = myBot.Chat(request);
     SpeechSynth.Speak(result.Output);
     return (result.Output);
 }
开发者ID:andrehendriks,项目名称:AutonomousComputerProgram-Missy,代码行数:8,代码来源:Missy.cs

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

示例15: SayText

 /// <summary>
 /// Speak the supplied text, using the supplied volume level
 /// </summary>
 /// <param name="spoken_text">A string containing the text to speak</param>
 /// <param name="volume">An integer, in the range 0-100, specifying the volume level to use</param>
 public static void SayText(string spoken_text, int volume)
 {
     using (SpeechSynthesizer speaker = new SpeechSynthesizer())
     {
         speaker.Volume = volume;
         speaker.Speak(spoken_text);
     }
 }
开发者ID:TheProjecter,项目名称:speakingclock,代码行数:13,代码来源:SpeakTime.cs


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