private static byte[] StartSpeak(string word)
        {
            var ms = new MemoryStream();
            using (System.Speech.Synthesis.SpeechSynthesizer synhesizer = new System.Speech.Synthesis.SpeechSynthesizer())
            {
                foreach (var voice in synhesizer.GetInstalledVoices())
                {
                    Console.WriteLine("select(y/n): " + voice.VoiceInfo.Name);
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Y)
                    {
                        synhesizer.SelectVoice(voice.VoiceInfo.Name);
                        synhesizer.SelectVoiceByHints(voice.VoiceInfo.Gender, voice.VoiceInfo.Age, 1, voice.VoiceInfo.Culture);
                        synhesizer.SetOutputToWaveStream(ms);
                        synhesizer.Speak(word);
                    }
                }
            }

            return ms.ToArray();
        }
Esempio n. 2
0
        private void AlarmControlTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                TimeSpan TimeRest = default;
                if (AlarmClockTime.TimeOfDay < DateTime.Now.TimeOfDay)
                {
                    RunningTime -= TimeSpan.FromMilliseconds(1000);
                    TimeRest    -= RunningTime;
                }
                else
                {
                    TimeRest = AlarmClockTime - DateTime.Now;
                }

                AlarmControlLabel.Text = $"{Math.Abs(TimeRest.Hours)}" +
                                         $"H:{Math.Abs(TimeRest.Minutes)}" +
                                         $"M:{Math.Abs(TimeRest.Seconds)}S";

                if (TimeRest.Hours == 0 && TimeRest.Minutes == 0 && TimeRest.Seconds == 0)
                {
                    var Thread = new System.Threading.Thread(() =>
                    {
                        using (Speech = new System.Speech.Synthesis.SpeechSynthesizer())
                        {
                            Speech.Volume = 100;

                            int i = 0;
                            while (Speech != null && i++ != 10)
                            {
                                Speech?.Speak("Get up, leather bag, time to work");
                            }

                            this.Invoke((System.Action) delegate()
                            {
                                AlarmControlTimer.Enabled = false;
                                Speech = null;
                                AlarmControlInputTimeTextBox.Text = "";
                                AlarmControlLabel.Text            = "00H:00M:00S";
                            });
                        }
                    });

                    Thread.IsBackground = true;
                    Thread.Start();

                    if (Thread.IsAlive)
                    {
                        AlarmControlTimer.Enabled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(),
                                ex.GetType().Name,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     var syn = new System.Speech.Synthesis.SpeechSynthesizer();
     syn.SelectVoice("Microsoft Server Speech Text to Speech Voice (ja-JP, Haruka)");
     syn.Speak("こんにちは");
 }
        private void ButtonVoiceSpecimenDescription_Click(object sender, RoutedEventArgs e)
        {
            using (System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer())
            {
                synth.SetOutputToDefaultAudioDevice();

                System.Speech.Synthesis.PromptBuilder builder = new System.Speech.Synthesis.PromptBuilder();
                builder.AppendTextWithHint("S12", System.Speech.Synthesis.SayAs.NumberCardinal);
                builder.AppendTextWithHint("10456", System.Speech.Synthesis.SayAs.SpellOut);

                synth.Speak(builder);
            }
        }
Esempio n. 5
0
 void engine_SpeechRecognized(object sender, System.Speech.Recognition.SpeechRecognizedEventArgs e)
 {
     System.Speech.Synthesis.SpeechSynthesizer reader = new System.Speech.Synthesis.SpeechSynthesizer();
     System.Speech.Recognition.SpeechRecognitionEngine engine = new System.Speech.Recognition.SpeechRecognitionEngine();
     try
     {
         engine = new System.Speech.Recognition.SpeechRecognitionEngine();
         String message = "";
         String results = e.Result.Text;
         if (!listening)
         {
             return;
         }
         switch (results)
         {
             case "help":
                 reader.Speak("The available commands are restart, shutdown, status report, and players.");
                 Logger.Log(LogType.ConsoleOutput, "The available commands are restart, shutdown, status report, and a players.");
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "restart":
                 reader.Speak("The server is now restarting.");
                 ShutdownParams param = new ShutdownParams(ShutdownReason.Restarting, TimeSpan.FromSeconds(5), true, true, "Restarting", Player.Console);
                 Server.Shutdown(param, true);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "shutdown":
                 reader.Speak("The server is now shutting down.");
                 Shutdown(ShutdownReason.ShuttingDown, true);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "status report":
                 reader.Speak("Server has been up for " + Math.Round(DateTime.UtcNow.Subtract(Server.StartTime).TotalHours, 1, MidpointRounding.AwayFromZero) + " hours.");
                 Player.Console.ParseMessage("/sinfo", true, false);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "players":
                 foreach (Player p in Server.Players)
                 {
                     message += p.Name;
                 }
                 reader.Speak(message);
                 Player.Console.ParseMessage("/players", true, false);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             default:
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
         }
     }
     catch(Exception)
     {
         //Audio Device is either missing or damaged, actual Exception is System.Speech.Internal.Synthesis.AudioException
         engine.RecognizeAsyncStop();
         engine.Dispose();
         return;
     }
 }
Esempio n. 6
0
        /// <summary>调用语音引擎说出指定话</summary>
        /// <param name="value"></param>
        public static void Speak(this String value)
        {
            Init();

            _provider.Speak(value);
        }
        public System.IO.MemoryStream Speak(string phrase, string culture, string voice, int volume, int rate)
        {
            try
            {                                                   // paranoia here..
                System.Speech.Synthesis.PromptBuilder pb;

                if (culture.Equals("Default"))
                {
                    pb = new System.Speech.Synthesis.PromptBuilder();
                }
                else
                {
                    try
                    {
                        pb = new System.Speech.Synthesis.PromptBuilder(new System.Globalization.CultureInfo(culture)); // may except if crap culture for machine
                    }
                    catch
                    {
                        pb = new System.Speech.Synthesis.PromptBuilder();
                    }
                }


                if (voice.Equals("Female", StringComparison.InvariantCultureIgnoreCase))
                {
                    pb.StartVoice(System.Speech.Synthesis.VoiceGender.Female);
                }
                else if (voice.Equals("Male", StringComparison.InvariantCultureIgnoreCase))
                {
                    pb.StartVoice(System.Speech.Synthesis.VoiceGender.Male);
                }
                else if (!voice.Equals("Default", StringComparison.InvariantCultureIgnoreCase))
                {
                    pb.StartVoice(voice);
                }
                else
                {
                    pb.StartVoice(systemdefaultvoice);
                }

                synth.Volume = volume;
                synth.Rate   = rate;

                //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Speak " + phrase + ", Rate " + rate + " culture " + culture);

                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                synth.SetOutputToWaveStream(stream);

                string[] ssmlstart = new string[] { "<say-as ", "<emphasis", "<phoneme", "<sub", "<prosody" };
                string[] ssmlend   = new string[] { "</say-as>", "</emphasis>", "</phoneme>", "</sub>", "</prosody>" };

                phrase.Trim();

                while (phrase.Length > 0)
                {
                    int ssmlindex;
                    int foundpos = phrase.IndexOf(ssmlstart, out ssmlindex); // find one of the ssml phrases
                    if (foundpos == -1)                                      // no more, task on rest as normal text
                    {
                        pb.AppendText(phrase);
                        break;
                    }
                    else
                    {
                        if (foundpos > 0)
                        {
                            pb.AppendText(phrase.Substring(0, foundpos));       // tack on front
                            phrase = phrase.Substring(foundpos);
                        }

                        int indexofend = phrase.IndexOf(ssmlend[ssmlindex]);

                        if (indexofend == -1) // allowed as a shortcut to drop the last one
                        {
                            indexofend = phrase.Length;
                            phrase    += ssmlend[ssmlindex];
                        }

                        indexofend += ssmlend[ssmlindex].Length; // move to end of it

                        string ssmlcmd = phrase.Substring(0, indexofend).Replace('\'', '"');

                        //for (int i = 0; i < ssmlcmd.Length; i++) System.Diagnostics.Debug.WriteLine("SSML :" + (int)ssmlcmd[i] + " = " + ssmlcmd[i]);

                        try
                        {
                            pb.AppendSsmlMarkup(ssmlcmd);
                        }
                        catch       // bad markup
                        {
                            pb.AppendText("Bad SSML Markup when added, contact developers");
                        }

                        phrase = phrase.Substring(indexofend).Trim();
                    }
                }

                pb.EndVoice();

                try
                {
                    synth.Speak(pb);
                }
                catch
                {
                    synth.Speak("Bad SSML Markup in phrase, your chosen voice may not support all options. See voice configuration menu to disable SSML");
                }

                //System.Diagnostics.Debug.WriteLine("Speech " + stream.Length);
                return(stream);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception " + ex.ToString());
                return(null);
            }
        }
Esempio n. 8
0
        private static void Alarm(string text)
        {
            System.Speech.Synthesis.SpeechSynthesizer p_objSynth = new System.Speech.Synthesis.SpeechSynthesizer();

            p_objSynth.Speak(text);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            var speach = new System.Speech.Synthesis.SpeechSynthesizer();

            speach.Speak("You mean to tell me!");
        }
Esempio n. 10
0
        void engine_SpeechRecognized(object sender, System.Speech.Recognition.SpeechRecognizedEventArgs e)
        {
            System.Speech.Synthesis.SpeechSynthesizer         reader = new System.Speech.Synthesis.SpeechSynthesizer();
            System.Speech.Recognition.SpeechRecognitionEngine engine = new System.Speech.Recognition.SpeechRecognitionEngine();
            try
            {
                engine = new System.Speech.Recognition.SpeechRecognitionEngine();
                String message = "";
                String results = e.Result.Text;
                if (!listening)
                {
                    return;
                }
                switch (results)
                {
                case "help":
                    reader.Speak("The available commands are restart, shutdown, status report, and players.");
                    Logger.Log(LogType.ConsoleOutput, "The available commands are restart, shutdown, status report, and a players.");
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "restart":
                    reader.Speak("The server is now restarting.");
                    ShutdownParams param = new ShutdownParams(ShutdownReason.Restarting, TimeSpan.FromSeconds(5), true, true, "Restarting", Player.Console);
                    Server.Shutdown(param, true);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "shutdown":
                    reader.Speak("The server is now shutting down.");
                    Shutdown(ShutdownReason.ShuttingDown, true);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "status report":
                    reader.Speak("Server has been up for " + Math.Round(DateTime.UtcNow.Subtract(Server.StartTime).TotalHours, 1, MidpointRounding.AwayFromZero) + " hours.");
                    Player.Console.ParseMessage("/sinfo", true, false);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "players":
                    foreach (Player p in Server.Players)
                    {
                        message += p.Name;
                    }
                    reader.Speak(message);
                    Player.Console.ParseMessage("/players", true, false);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                default:
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;
                }
            }
            catch (Exception)
            {
                //Audio Device is either missing or damaged, actual Exception is System.Speech.Internal.Synthesis.AudioException
                engine.RecognizeAsyncStop();
                engine.Dispose();
                return;
            }
        }
Esempio n. 11
0
 public static void Speak(this string value)
 {
     System.Speech.Synthesis.SpeechSynthesizer ssy = new System.Speech.Synthesis.SpeechSynthesizer();
     ssy.Speak(value);
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 public void talk(string textTSpeak)
 {
     m_mainTalker.Speak(textTSpeak);
 }