Beispiel #1
0
        private void WAVLocationDialog_FileOk(object sender, CancelEventArgs e)
        {
            s.SetOutputToWaveFile(WAVLocationDialog.FileName);
            s.Speak(SpeechText.Text);

            System.Diagnostics.Process.Start(new System.IO.FileInfo(WAVLocationDialog.FileName).DirectoryName);
        }
Beispiel #2
0
        public override bool SynthesizeAsync(string content, string fileName = null)
        {
            if (fileName == null)
            {
                OutputMode = OutputMode.扬声器;
                NativeSynthesizer.SetOutputToDefaultAudioDevice();
            }
            else
            {
                OutputMode = OutputMode.文件;
                NativeSynthesizer.SetOutputToWaveFile(fileName);
            }

            Task.Run(() =>
            {
                SynthesizerState = SynthesizerState.合成;

                NativeSynthesizer.Speak(content);

                SynthesizerState = SynthesizerState.空闲;
            });

            this.Info("合成:" + content);

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// 生成语音文件的方法
        /// </summary>
        /// <param name="text"></param>
        private static void SaveFile(string text)
        {
            using (System.Speech.Synthesis.SpeechSynthesizer speechSyn = new System.Speech.Synthesis.SpeechSynthesizer())
            {
                speechSyn.Volume = 100;
                speechSyn.Rate   = 0;
                string strPath = @"F:\研发一部\5.源代码\6.组件库\Lxsh.Project\Lxsh.Project.SpeechSynthesizer.Demo\bin\Debug\1.mp3";
                speechSyn.SetOutputToWaveFile(strPath);

                speechSyn.Speak(text);
                speechSyn.SetOutputToNull();
            }
        }
Beispiel #4
0
 private void speak(bool bAsync, System.Speech.Synthesis.PromptBuilder pb)
 {
     try
     {
         if (bSaveFile)
         {
             ss.SetOutputToNull();
             delOutFile();
             ss.SetOutputToWaveFile(strOutputFile);
         }
         if (bAsync)
         {
             ss.SpeakAsync(pb);
         }
         else
         {
             ss.Speak(pb);
         }
     }
     catch (Exception ex)
     {
         speak("An error occured:" + ex.Message, false);
     }
 }
        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();
        }
Beispiel #6
0
        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;
            }
        }