private void bntConvert_Click(object sender, EventArgs e) { string age = cbVoiceAge.SelectedItem.ToString(); string gender = cbVoiceGender.SelectedItem.ToString(); string text = txtTexttoSpeak.Text.ToString(); System.Speech.Synthesis.SpeechSynthesizer newvoice = Setupvoice(gender, age); newvoice.SetOutputToWaveFile(dir + @"\" + filename + ".wav", new SpeechAudioFormatInfo(8000, AudioBitsPerSample.Eight, AudioChannel.Mono)); System.Media.SoundPlayer m_SoundPlayer = new System.Media.SoundPlayer(dir + @"\" + filename + ".wav"); newvoice.Speak(text); m_SoundPlayer.Play(); newvoice.Dispose(); }
public void read_aloud_html(string inHtml, string audir, string voicename, int startID) { try { System.Speech.Synthesis.SpeechSynthesizer l_spv = new System.Speech.Synthesis.SpeechSynthesizer(); l_spv.SpeakCompleted += new EventHandler <System.Speech.Synthesis.SpeakCompletedEventArgs>(spv_SpeakCompleted); l_spv.SpeakProgress += new EventHandler <System.Speech.Synthesis.SpeakProgressEventArgs>(spv_SpeakProgress); l_spv.SelectVoice(voicename); l_spv.Rate = -2; l_spv.SetOutputToWaveFile(audir + "\\audio.wav"); audioComplete = false; spanTxt = ""; smilTxt = ""; last_time = ""; curFullTxt = ""; curFullTxt = inHtml; spanID = startID; spanPoint = 0; curPageHtml = "page.html"; curaudioFile = "audio.mp3"; probar.Visible = true; probar.Maximum = Regex.Matches(inHtml, "\\s").Count; probar.Value = 0; l_spv.SpeakAsync(inHtml); while (audioComplete == false) { Application.DoEvents(); } string wSmil = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; wSmil += "<smil xmlns=\"http://www.w3.org/ns/SMIL\" version=\"3.0\" profile=\"http://www.idpf.org/epub/30/profile/content/\">\n"; wSmil += "<body>\n"; wSmil += smilTxt; wSmil += "\n</body></smil>\n"; txt_smil.Text = wSmil; txt_out.Text = htLineTxt; // File.WriteAllText(htmlDir + "\\page" + pgNum + ".smil", wSmil); probar.Visible = false; l_spv.Dispose(); //write mp3 file convert_mp3(audir); if (File.Exists(txt_savefile.Text)) { File.Delete(txt_savefile.Text); } File.Copy(audir + "\\audio.mp3", txt_savefile.Text, true); gCls.show_message("SMIL Tag generated successfully"); } catch (Exception erd) { gCls.show_error(erd.Message.ToString()); return; } }