Exemplo n.º 1
1
        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();
        }
Exemplo n.º 2
0
        private void speakAll()
        {
            synthesizer = new System.Speech.Synthesis.SpeechSynthesizer();
            CultureInfo culture = new CultureInfo("en-US");

            synthesizer.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Teen, 1, culture);

            List <string> lis = new List <string>(174);

            foreach (var it in colorsArray)
            {
                lis.Add(colorsArray.ToString());
            }
            // System.Threading.Thread.Sleep(20000);
            Random random = new Random();
            int    item   = 0;
            int    count  = lis.Count;

            for (int i = 0; i <= count; i++)
            {
                item = random.Next(0, lis.Count);
                synthesizer.Speak(lis[item]);
                lis.Remove(lis[item]);
            }
        }
Exemplo n.º 3
0
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            synthesizer = new System.Speech.Synthesis.SpeechSynthesizer();
            CultureInfo culture = new CultureInfo("en-US");

            synthesizer.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Teen, 1, culture);
            synthesizer.Speak(listBox1.SelectedItem.ToString());
        }
Exemplo n.º 4
0
        static void SayString(string s)
        {
            System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();

            synth.SetOutputToDefaultAudioDevice();
            synth.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Senior);
            synth.Volume = 100;
            synth.Rate   = 0;
            synth.Speak(s);
        }
Exemplo n.º 5
0
 public void Play()
 {
     using (var synth = new System.Speech.Synthesis.SpeechSynthesizer())
     {
         synth.SelectVoiceByHints((System.Speech.Synthesis.VoiceGender)VoiceGender, (System.Speech.Synthesis.VoiceAge)VoiceAge, VoicePosition, new CultureInfo(CultureInfo));
         synth.SetOutputToDefaultAudioDevice();
         synth.Volume = Volume;
         synth.Rate   = Rate;
         synth.Speak(Text);
     }
 }
Exemplo n.º 6
0
        public override void Speak(string text, bool gender, int ipitch)
        {
            var Synth = new System.Speech.Synthesis.SpeechSynthesizer();

            Synth.SelectVoiceByHints((gender) ? System.Speech.Synthesis.VoiceGender.Female : System.Speech.Synthesis.VoiceGender.Male);
            if (text == "")
            {
                return;
            }
            var voci   = Synth.GetInstalledVoices();
            var stream = new System.IO.MemoryStream();
            var pitch  = Math.Max(0.1f, ipitch / 100f + 1f); //below 0.1 is just stupid, so just clamp there.

            if (pitch < 1f)
            {
                Synth.Rate = 10 - (int)(pitch * 10);
            }
            else
            {
                Synth.Rate = (int)(10 / pitch) - 10;
            }
            Synth.SetOutputToWaveStream(stream);
            Synth.SpeakAsync(text);

            EventHandler <System.Speech.Synthesis.SpeakCompletedEventArgs> OnComplete = null;

            OnComplete = (obj, evt) =>
            {
                GameThread.NextUpdate((u) =>
                {
                    stream.Seek(0, System.IO.SeekOrigin.Begin);
                    var sfx    = SoundEffect.FromStream(stream);
                    var inst   = sfx.CreateInstance();
                    inst.Pitch = pitch - 1f;
                    inst.Play();

                    GameThreadInterval interval = null;
                    interval = GameThread.SetInterval(() =>
                    {
                        if (inst.State == SoundState.Stopped)
                        {
                            sfx.Dispose(); //just catch and dispose these when appropriate
                            interval.Clear();
                        }
                    }, 1000);
                    Synth.Dispose();
                });
                Synth.SpeakCompleted -= OnComplete;
            };

            Synth.SpeakCompleted += OnComplete;
        }
Exemplo n.º 7
0
        public SoundHandler()
        {
            cat = new System.Speech.Synthesis.SpeechSynthesizer();
            cat.SetOutputToDefaultAudioDevice();
            cat.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Teen, 0, new System.Globalization.CultureInfo("zh-Hans"));
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = new System.Random().Next(60000 * 60, 120000 * 60);
            timer.Elapsed += CallBack;
            timer.Enabled  = true;

            FailSound    = "";
            SuccessSound = "";
        }
Exemplo n.º 8
0
 public static async System.Threading.Tasks.Task <Byte[]> TextToSpeechServiceAsync(string text, System.Collections.Generic.Dictionary <string, string> apiArgs)
 {
     Log.WriteLine("text:\"" + text + "\"");
     //System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(Options.options.locale.language);
     using (System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer())
     {
         // Explicitly specify audio settings. All services are ok with 16000/16/1. It's ok to cast options to enums as their values are identical.
         int sampleRate = int.Parse(apiArgs["sampleRate"]);
         System.Speech.AudioFormat.SpeechAudioFormatInfo si = new System.Speech.AudioFormat.SpeechAudioFormatInfo(sampleRate, (System.Speech.AudioFormat.AudioBitsPerSample)WoundifyShared.Options.options.audio.bitDepth, (System.Speech.AudioFormat.AudioChannel)WoundifyShared.Options.options.audio.channels);
         // TODO: use memory based file instead
         synth.SetOutputToWaveFile(Options.options.tempFolderPath + Options.options.audio.speechSynthesisFileName, si);
         synth.SelectVoiceByHints((System.Speech.Synthesis.VoiceGender)Options.commandservices["TextToSpeech"].voiceGender, (System.Speech.Synthesis.VoiceAge)Options.commandservices["TextToSpeech"].voiceAge);
         synth.Speak(text);
     }
     return(await Helpers.ReadBytesFromFileAsync(Options.options.audio.speechSynthesisFileName));
 }
Exemplo n.º 9
0
 public static void TTSspeak(string text)
 {
     using (var ss = new System.Speech.Synthesis.SpeechSynthesizer())
     {
         ss.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Adult, 0, System.Globalization.CultureInfo.GetCultureInfo("en-US"));
         //var pr = ss.SpeakAsync(text);
         //Task.Run(() =>
         //{
         //    do
         //    {
         //        Application.DoEvents();
         //        System.Threading.Thread.Sleep(1000);
         //    } while (!pr.IsCompleted);
         //}).Wait();
         ss.Speak(text);
     }
 }
Exemplo n.º 10
0
 public override void Speak(string text, bool gender)
 {
     Synth.SelectVoiceByHints((gender) ? System.Speech.Synthesis.VoiceGender.Female : System.Speech.Synthesis.VoiceGender.Male);
     Synth.SpeakAsync(text);
 }