/// <summary> /// 执行启动过程的具体步骤. /// </summary> /// <returns>成功返回True, 否则返回False.</returns> /// <remarks> /// 若启动过程有多个步骤, 遇到返回错误的步骤立即停止向下执行. /// </remarks> protected override bool StartCore() { if (!base.StartCore()) { return(false); } var synthesizer = new NativeSynthesizer(); ChineseVoices = synthesizer.GetInstalledVoices(new CultureInfo("zh-CN")); EnglishVoices = synthesizer.GetInstalledVoices(new CultureInfo("en-US")); return(true); }
public Form1() { InitializeComponent(); // Initialize a new instance of the SpeechSynthesizer. _synth = new SpeechSynthesis.SpeechSynthesizer(); // Configure the audio output. _synth.SetOutputToDefaultAudioDevice(); var installedVoices = _synth.GetInstalledVoices(); this.AllowDrop = true; this.DragEnter += new DragEventHandler(Form1_DragEnter); this.DragDrop += new DragEventHandler(Form1_DragDrop); _voices = new List <string>(); _voices.AddRange(installedVoices.Select(x => $"{x.VoiceInfo.Name}# {x.VoiceInfo.Gender} {x.VoiceInfo.Culture}")); comboBoxVoices.DataSource = _voices; var wordVersion = IsWordInteropInstalled(); if (wordVersion != null) { toolStripStatusLabel1.Text = $"Word interpop found: {wordVersion}"; } else { toolStripStatusLabel1.Text = "Warning: Word interop not found"; } Text = $"Test Speech {Assembly.GetExecutingAssembly().GetName().Version.ToString()}"; // notifyIcon1.ContextMenu = contextMenuStrip1; }
static void Main(string[] args) { System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer(); List <InstalledVoice> voices = new List <InstalledVoice>(); voices.AddRange(synth.GetInstalledVoices(new CultureInfo("en-GB"))); voices.AddRange(synth.GetInstalledVoices(new CultureInfo("en-US"))); // synth.Voice. synth.SpeakAsync(@"one two three blarg! Shoe shop event horizon. bannana puding to the nth degree poisoning pigeons in the park"); Console.Read(); synth.SpeakAsyncCancelAll(); }
public static void reportVoices() { try { SpeechSynthesizer ss = new System.Speech.Synthesis.SpeechSynthesizer(); for (int i = 0; i < ss.GetInstalledVoices().Count; i++) { LoggingHelper.log(ss.GetInstalledVoices()[i].VoiceInfo.Name); } } catch (Exception ex) { throw ex; } finally { } }
public List <string> GetInstalledVoices() { List <string> InstalledVoices = new List <string>(); using (System.Speech.Synthesis.SpeechSynthesizer aSynth = new System.Speech.Synthesis.SpeechSynthesizer()) { foreach (InstalledVoice voices in aSynth.GetInstalledVoices()) { if (voices.Enabled) { InstalledVoices.Add(voices.VoiceInfo.Name); } } } return(InstalledVoices); }
private Speech() { SpeechConfig config = SpeechConfig.FromSubscription(API_KEY, REGION); config.SpeechRecognitionLanguage = "de-DE"; _recognizer = new SpeechRecognizer(config); _synthesizer = new System.Speech.Synthesis.SpeechSynthesizer(); ICollection <InstalledVoice> voices = _synthesizer.GetInstalledVoices(System.Globalization.CultureInfo.CreateSpecificCulture("de-DE")); foreach (InstalledVoice voice in voices) { _synthesizer.SelectVoice(voice.VoiceInfo.Name); } //_synthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult); }
private void VoiceSelection_Load(object sender, EventArgs e) { this.MaximumSize = this.Size; this.MinimumSize = this.Size; Voice.SetOutputToDefaultAudioDevice(); System.Speech.Synthesis.SpeechSynthesizer VoiceRetrieval = new System.Speech.Synthesis.SpeechSynthesizer(); Voices = new List <System.Speech.Synthesis.InstalledVoice>(); Voices.AddRange(VoiceRetrieval.GetInstalledVoices()); foreach (System.Speech.Synthesis.InstalledVoice Voice in Voices) { VoicesListBox.Items.Add(Voice.VoiceInfo.Name + " Gender: " + Voice.VoiceInfo.Gender + " Culture: " + Voice.VoiceInfo.Culture.NativeName); } }
//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) { } } }
private void Form1_Load(object sender, EventArgs e) { strGrammarFile = asr.GetValue("strGrammarFile", "".GetType()).ToString(); foreach (System.Speech.Synthesis.InstalledVoice iv in ss.GetInstalledVoices()) { SSS.VoiceInfo vi = iv.VoiceInfo; string strName = vi.Name + "/" + vi.Age.ToString() + "/" + vi.Gender.ToString() + "/" + vi.Culture.DisplayName; ToolStripItem tsi = setVoiceToolStripMenuItem.DropDownItems.Add(strName); tsi.Tag = vi.Name; tsi.Click += new EventHandler(tsi_Click); } sre.SpeechDetected += new EventHandler <System.Speech.Recognition.SpeechDetectedEventArgs>(sre_SpeechDetected); sre.SpeechRecognized += new EventHandler <System.Speech.Recognition.SpeechRecognizedEventArgs>(sre_SpeechRecognized); ss.SpeakStarted += new EventHandler <System.Speech.Synthesis.SpeakStartedEventArgs>(ss_SpeakStarted); ss.SpeakCompleted += new EventHandler <System.Speech.Synthesis.SpeakCompletedEventArgs>(ss_SpeakCompleted); loadGrammar(); sre.SetInputToDefaultAudioDevice(); sre.RecognizeAsync(SSR.RecognizeMode.Multiple); }
//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); }
public static async Task RecognizeOnceSpeechAsync(SpeechTranslationConfig config) { var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures); // Creates a speech recognizer. using (var recognizer = new IntentRecognizer(config)) { Console.WriteLine("Say something..."); var model = LanguageUnderstandingModel.FromAppId(ConfigurationManager.AppSettings.Get("LUISId")); recognizer.AddAllIntents(model); var result = await recognizer.RecognizeOnceAsync(); // Checks result. if (result.Reason == ResultReason.RecognizedIntent) { Console.WriteLine($"RECOGNIZED: Text={result.Text}"); Console.WriteLine($" Intent Id: {result.IntentId}."); Console.WriteLine($" Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}."); if (result.IntentId == "Translate") { var luisJson = JObject.Parse(result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)); string targetLng = luisJson["entities"].First(x => x["type"].ToString() == "TargetLanguage")["entity"].ToString(); string text = luisJson["entities"].First(x => x["type"].ToString() == "Text")["entity"].ToString(); var lng = allCultures.FirstOrDefault(c => c.DisplayName.ToLower() == targetLng.ToLower()) ?? allCultures.FirstOrDefault(c => c.DisplayName.ToLower() == "english"); var translated = Translate.TranslateText("de-DE", text); Console.WriteLine("Translation: " + translated); var synth = new System.Speech.Synthesis.SpeechSynthesizer(); // Configure the audio output. synth.SetOutputToDefaultAudioDevice(); // Speak a string. synth.SelectVoice(synth.GetInstalledVoices().First(x => x.VoiceInfo.Culture.TwoLetterISOLanguageName == lng.TwoLetterISOLanguageName).VoiceInfo.Name); synth.Speak(translated); } } else if (result.Reason == ResultReason.RecognizedSpeech) { Console.WriteLine($"RECOGNIZED: Text={result.Text}"); Console.WriteLine($" Intent not recognized."); } else if (result.Reason == ResultReason.NoMatch) { Console.WriteLine($"NOMATCH: Speech could not be recognized."); } else if (result.Reason == ResultReason.Canceled) { var cancellation = CancellationDetails.FromResult(result); Console.WriteLine($"CANCELED: Reason={cancellation.Reason}"); if (cancellation.Reason == CancellationReason.Error) { Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}"); Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}"); Console.WriteLine($"CANCELED: Did you update the subscription info?"); } } } }
// <----------------database comms----------------> private int submit(String query) { // 2 = individual id ; 1 = family id ; 0 = other, should be name int queryType = DbHelper.classify(query); // Get things from the database, which // Stores result in the SearchHelper Data Table of DbHelper class. /*if (queryType == 2) // Query is an individual id * { * DbHelper.searchByIdForIndividuals(query.Replace(" ", "").Replace("%", "")); * }*/ if (queryType == 1) // Query is a family id { DbHelper.searchByIdForFamilies(query.Replace(" ", "")); } if (queryType == 0) // Query is a name { String[] queries = query.Split(' '); DataTable result = null; foreach (String q in queries) { if (q == "") { continue; } DataTable toAdd = DbHelper.searchByName(q); if (result == null) { result = toAdd; } else { result.Merge(toAdd); } } result = DbHelper.RemoveDupes(result); if (result == null) { result = new DataTable(); } DbHelper.copyToSearchHelper(result); } DataTable table = DbHelper.SearchHelper; if (table == null) { return(-1); } int numberOfRowsInQueryResult = table.Rows.Count; Family selectedMember = getMemberSelection(numberOfRowsInQueryResult); if (selectedMember != null) { selectedMember.LoginTime = DateTime.Now; viewModel.Login(selectedMember); viewModel.ForceUpdateHistoryReportTextCommand.Execute(null); // show installed voices foreach (var v in speaker.GetInstalledVoices().Select(v => v.VoiceInfo)) { Console.WriteLine("Name:{0}, Gender:{1}, Age:{2}", v.Description, v.Gender, v.Age); } speaker.SpeakAsync(selectedMember.Greeting); return(1); } if (selectedMember == null) { /*if (numberOfRowsInQueryResult > 0) // User cancelled * { * db.DoDisplayError = true; * db.ErrorMessage = "Cancelled"; * db.ErrorDisplayRule = "TextChanged"; * * db.ForceValidateCommand.Execute(null); * }*/ if (numberOfRowsInQueryResult == 0) // Search returned no results { if (LoginViewModel.DoDisplayError != true) // if Error not already set in DbHelper due to unavailability of database file { LoginViewModel.DoDisplayError = true; LoginViewModel.ErrorMessage = "No members match the criteria"; LoginViewModel.ErrorDisplayRule = "TextChanged"; viewModel.ForceValidateCommand.Execute(null); } } } return(-1); }
//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; }