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(); }
public string GetVoices() { if (this.synthesizerType == "Azure") { RenewToken(); return(SynthesisGetAvailableVoicesAsync().Result); } else { using var synth = new System.Speech.Synthesis.SpeechSynthesizer(); try { synth.InjectOneCoreVoices(); } catch { } string voices = ""; foreach (var voice in synth.GetInstalledVoices()) { if (voices.Length > 0) { voices += "|"; } voices += voice.VoiceInfo.Name + " (" + voice.VoiceInfo.Culture.Name + ")"; } return(voices); } }
public List <string> getSystemVoices() { List <string> voices = new List <string> (); #if __WIN32__ using (var speech = new SpeechEngine()) { var voicelist = speech.GetInstalledVoices(); foreach (InstalledVoice v in voicelist) { if (v.Enabled) { Console.WriteLine(v.VoiceInfo.Name); voices.Add(v.VoiceInfo.Name); } } } #else NSApplication.SharedApplication.InvokeOnMainThread(() => { foreach (var voice in SpeechEngine.AvailableVoices) { voices.Add(voice); } }); #endif return(voices); }
private void button1_Click(object sender, EventArgs e) { foreach (var v in synthesizer.GetInstalledVoices().Select(v => v.VoiceInfo)) { listBox1.Items.Add(v.Description); } }
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; }
//------------------------------------------------------------------------------------------------------------------------------- public void Init() { System.Speech.Synthesis.SpeechSynthesizer mySynth = new System.Speech.Synthesis.SpeechSynthesizer(); var Voices = mySynth.GetInstalledVoices(); for (int count = 0; count < Voices.Count; count++) { if (Voices[count].VoiceInfo.Name.ToLowerInvariant().Contains("hazel")) { mySynth.SelectVoice(Voices[count].VoiceInfo.Name); break; } } m_mainTalker = mySynth; }
public static Tuple <List <string>, List <string> > GetLanguageVoice() { //Microsoft.Speech.Synthesis.SpeechSynthesizer msftSynth = new Microsoft.Speech.Synthesis.SpeechSynthesizer(); System.Speech.Synthesis.SpeechSynthesizer sysSynth = new System.Speech.Synthesis.SpeechSynthesizer(); List <string> languageList = new List <string>(); List <string> voiceList = new List <string>(); /* * foreach (Microsoft.Speech.Synthesis.InstalledVoice voice in msftSynth.GetInstalledVoices()) * { * Microsoft.Speech.Synthesis.VoiceInfo info = voice.VoiceInfo; * Console.WriteLine("==================================="); * Console.WriteLine(" Name: " + info.Name); * Console.WriteLine(" Culture: " + info.Culture); * Console.WriteLine(" ID: " + info.Id); * if (!languageList.Contains(info.Culture.ToString())) * languageList.Add(info.Culture.ToString()); * if (!voiceList.Contains(info.Name)) * voiceList.Add(info.Name); * } * */ foreach (System.Speech.Synthesis.InstalledVoice voice in sysSynth.GetInstalledVoices()) { System.Speech.Synthesis.VoiceInfo info = voice.VoiceInfo; //Console.WriteLine("==================================="); //Console.WriteLine(" Name: " + info.Name); //Console.WriteLine(" Culture: " + info.Culture); // Console.WriteLine(" ID: " + info.Id); if (!languageList.Contains(info.Culture.ToString())) { languageList.Add(info.Culture.ToString()); } if (!voiceList.Contains(info.Name)) { voiceList.Add(info.Name); } } return(new Tuple <List <string>, List <string> >(languageList, voiceList)); }
public string[] GetVoiceNames() { return(synth.GetInstalledVoices().Select(v => v.VoiceInfo.Name).ToArray()); }
public List<string> getSystemVoices() { List<string> voices = new List<string> (); #if __WIN32__ using(var speech = new SpeechEngine()) { var voicelist = speech.GetInstalledVoices(); foreach(InstalledVoice v in voicelist) { if (v.Enabled) { Console.WriteLine(v.VoiceInfo.Name); voices.Add(v.VoiceInfo.Name); } } } #else NSApplication.SharedApplication.InvokeOnMainThread (() => { foreach (var voice in SpeechEngine.AvailableVoices) { voices.Add (voice); } }); #endif return voices; }