private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { Microsoft.Speech.Synthesis.SpeechSynthesizer ms = new Microsoft.Speech.Synthesis.SpeechSynthesizer(); ms.SetOutputToDefaultAudioDevice(); ms.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, Heami)"); switch (e.Result.Text) { case "마마고": { MaMaState(true); ms.Speak("네 말씀하세요"); sre2 = new SpeechRecognitionEngine(new CultureInfo("ko-KR")); Choices c = new Choices(); c.Add(new string[] { "입력해줘", "아니야", "영어로번역해줘", "한국어로번역해줘", "일본어로번역해줘", "독일어로번역해줘", "스페인어로번역해줘", "프랑스어로번역해줘", "러시아어로번역해줘", "이탈리아어로번역해줘", "중국어번체로번역해줘", "중국어간체로번역해줘" }); Microsoft.Speech.Recognition.Grammar g = new Microsoft.Speech.Recognition.Grammar(new GrammarBuilder(c)); sre2.LoadGrammar(g); sre2.RequestRecognizerUpdate(); sre2.SpeechRecognized += doWhat; sre2.SetInputToDefaultAudioDevice(); sre2.RecognizeAsync(RecognizeMode.Multiple); break; } } ms.Dispose(); return; }
//Show a list of installed languages for both System and Microsoft static void ShowInstalledLanguage() { using (System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer()) { try { foreach (System.Speech.Synthesis.InstalledVoice voice in synth.GetInstalledVoices()) { System.Speech.Synthesis.VoiceInfo info = voice.VoiceInfo; Console.WriteLine(" Name: " + info.Name); Console.WriteLine(" Culture: " + info.Culture); Console.WriteLine(" Age: " + info.Age); Console.WriteLine(" Gender: " + info.Gender); Console.WriteLine(" ID: " + info.Id); Console.WriteLine(); } } catch (Exception e) { } } using (Microsoft.Speech.Synthesis.SpeechSynthesizer synth = new Microsoft.Speech.Synthesis.SpeechSynthesizer()) { try { foreach (Microsoft.Speech.Synthesis.InstalledVoice voice in synth.GetInstalledVoices()) { Microsoft.Speech.Synthesis.VoiceInfo info = voice.VoiceInfo; Console.WriteLine(" Name: " + info.Name); Console.WriteLine(" Culture: " + info.Culture); Console.WriteLine(" Age: " + info.Age); Console.WriteLine(" Gender: " + info.Gender); Console.WriteLine(" ID: " + info.Id); Console.WriteLine(); } } catch (Exception e) { } } }
//Validate whether the string entered for voice selection is valid static Tuple <string, string> ValidateVoiceSelection(string inputVoiceString) { using (System.Speech.Synthesis.SpeechSynthesizer msftSynth = new System.Speech.Synthesis.SpeechSynthesizer()) { try { foreach (System.Speech.Synthesis.InstalledVoice voice in msftSynth.GetInstalledVoices()) { if (inputVoiceString.Equals(voice.VoiceInfo.Id) || inputVoiceString.Equals(voice.VoiceInfo.Name)) { synthesizerChoice = 1; return(new Tuple <string, string>(voice.VoiceInfo.Name, voice.VoiceInfo.Culture.ToString())); } } } catch (Exception e) { } } using (Microsoft.Speech.Synthesis.SpeechSynthesizer sysSynth = new Microsoft.Speech.Synthesis.SpeechSynthesizer()) { try { foreach (Microsoft.Speech.Synthesis.InstalledVoice voice in sysSynth.GetInstalledVoices()) { if (inputVoiceString.Equals(voice.VoiceInfo.Id) || inputVoiceString.Equals(voice.VoiceInfo.Name)) { synthesizerChoice = 2; return(new Tuple <string, string>(voice.VoiceInfo.Name, voice.VoiceInfo.Culture.ToString())); } } } catch (Exception e) { } } return(null); }
private void VoiceSpeak() { Microsoft.Speech.Synthesis.SpeechSynthesizer tts = new Microsoft.Speech.Synthesis.SpeechSynthesizer(); tts.SetOutputToDefaultAudioDevice(); string str = textBox2.Text; button3.Enabled = false; if (selectLanguage == true) { button3.Text = "Speaking"; } else if (selectLanguage == false) { button3.Text = "말하는중"; } if (t.Lang.Equals("ko") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, Heami)"); tts.Speak(str); } else if (t.Lang.Equals("ja") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (ja-JP, Haruka)"); tts.Speak(str); } else if (t.Lang.Equals("en") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-US, Helen)"); tts.Speak(str); } else if (t.Lang.Equals("de") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (de-De, Hedda)"); tts.Speak(str); } else if (t.Lang.Equals("es") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (es-ES, Helena)"); tts.Speak(str); } else if (t.Lang.Equals("fr") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (fr-FR, Hortense)"); tts.Speak(str); } //else if (t.Lang.Equals("zh-TW") == true) //{ // ts.SelectVoice("Microsoft Server Speech Text to Speech Voice (zh-TW, HanHan)"); // ts.Speak(str); //} //else if (t.Lang.Equals("zh-CN") == true) //{ // ts.SelectVoice("Microsoft Server Speech Text to Speech Voice (zh-CN, HuiHui)"); // ts.Speak(str); //} else if (t.Lang.Equals("ru") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (ru-RU, Elena)"); tts.Speak(str); } else if (t.Lang.Equals("it") == true) { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (it-IT, Lucia)"); tts.Speak(str); } else { tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-US, Helen)"); tts.Speak(str); } tts.Dispose(); button3.Enabled = true; if (selectLanguage == true) { button3.Text = "Voice"; } else if (selectLanguage == false) { button3.Text = "음성"; } }
private void doWhat(object sender, SpeechRecognizedEventArgs e2) { Microsoft.Speech.Synthesis.SpeechSynthesizer tts = new Microsoft.Speech.Synthesis.SpeechSynthesizer(); tts.SetOutputToDefaultAudioDevice(); tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, Heami)"); switch (e2.Result.Text) { case "입력해줘": { tts.Speak("네 입력할게요"); RecognizeSpeechAsync().Wait(); MaMaState(false); RecogStop(); break; } case "아니야": { tts.Speak("알겠습니다"); MaMaState(false); RecogStop(); break; } case "한국어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } ts.Speak("한국어로 번역해드릴게요"); ComboSet("한국어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "영어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("영어로 번역해드릴게요"); ComboSet("영어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "일본어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("일본어로 번역해드릴게요"); ComboSet("일본어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "독일어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("독일어로 번역해드릴게요"); ComboSet("독일어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "스페인어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("스페인어로 번역해드릴게요"); ComboSet("스페인어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "프랑스어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("프랑스어로 번역해드릴게요"); ComboSet("프랑스어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "러시아어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("러시아어로 번역해드릴게요"); ComboSet("러시아어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "이탈리아어로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("이탈리아어로 번역해드릴게요"); ComboSet("이탈리아어"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "중국어간체로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("중국어간체로 번역해드릴게요"); ComboSet("중국어간체"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } case "중국어번체로번역해줘": { if (textBox1.Text.Equals(string.Empty)) { tts.Speak("번역할 문장을 먼저 입력해주세요"); break; } tts.Speak("중국어번체로 번역해드릴게요"); ComboSet("중국어번체"); TranslateAtForm1(); MaMaState(false); RecogStop(); break; } } tts.Dispose(); return; }
//Validate whether the string entered for voice selection is valid static Tuple<string, string> ValidateVoiceSelection(string inputVoiceString) { using (System.Speech.Synthesis.SpeechSynthesizer msftSynth = new System.Speech.Synthesis.SpeechSynthesizer()) { try { foreach (System.Speech.Synthesis.InstalledVoice voice in msftSynth.GetInstalledVoices()) { if (inputVoiceString.Equals(voice.VoiceInfo.Id) || inputVoiceString.Equals(voice.VoiceInfo.Name)) { synthesizerChoice = 1; return new Tuple<string, string>(voice.VoiceInfo.Name, voice.VoiceInfo.Culture.ToString()); } } } catch (Exception e) { } } using (Microsoft.Speech.Synthesis.SpeechSynthesizer sysSynth = new Microsoft.Speech.Synthesis.SpeechSynthesizer()) { try { foreach (Microsoft.Speech.Synthesis.InstalledVoice voice in sysSynth.GetInstalledVoices()) { if (inputVoiceString.Equals(voice.VoiceInfo.Id) || inputVoiceString.Equals(voice.VoiceInfo.Name)) { synthesizerChoice = 2; return new Tuple<string, string>(voice.VoiceInfo.Name, voice.VoiceInfo.Culture.ToString()); } } } catch (Exception e) { } } return null; }