当前位置: 首页>>代码示例>>C#>>正文


C# SpeechSynthesizer.SetOutputToWaveFile方法代码示例

本文整理汇总了C#中SpeechSynthesizer.SetOutputToWaveFile方法的典型用法代码示例。如果您正苦于以下问题:C# SpeechSynthesizer.SetOutputToWaveFile方法的具体用法?C# SpeechSynthesizer.SetOutputToWaveFile怎么用?C# SpeechSynthesizer.SetOutputToWaveFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpeechSynthesizer的用法示例。


在下文中一共展示了SpeechSynthesizer.SetOutputToWaveFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            string voiceFileName = args[0];
            string voiceFileNamemp3 = voiceFileName.Replace(".wav", ".mp3");
            string voiceFilePath = args[1];
            string toBeVoiced = args[2];
            int rate = int.Parse(args[3]); ;
            string voice = args[4];

            voiceFileName = voiceFileName.Replace("~", " ");
            voiceFilePath = voiceFilePath.Replace("~", " ");
            toBeVoiced = toBeVoiced.Replace("~", " ");
            voice = voice.Replace("~", " ");

            var reader = new SpeechSynthesizer();
            reader.Rate = rate;
            reader.SelectVoice(voice);

            try
            {
                reader.SetOutputToWaveFile(voiceFilePath + voiceFileName, new SpeechAudioFormatInfo(16025, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
                reader.Speak(toBeVoiced);
                reader.Dispose();
                WaveToMP3(voiceFilePath + voiceFileName, voiceFilePath + voiceFileNamemp3);
            }
            catch (Exception er)
            {
                string s1 = er.Message;
            }
        }
开发者ID:connecticutortho,项目名称:ct-ortho-repositories4,代码行数:30,代码来源:Program.cs

示例2: button3_Click

 private void button3_Click(object sender, EventArgs e)
 {
     SpeechSynthesizer synth = new SpeechSynthesizer();
     synth.SetOutputToWaveFile(textBox2.Text);
     synth.Speak(textBox1.Text);
     synth.SetOutputToDefaultAudioDevice();
     MessageBox.Show("done");
 }
开发者ID:cr88192,项目名称:bgbtech_engine,代码行数:8,代码来源:Form1.cs

示例3: Speak

        public string Speak(string sText, bool bToFile)
        {
            SpeechSynthesizer oSpeaker = new SpeechSynthesizer();

            oSpeaker.Rate = 1;
            oSpeaker.SelectVoice("Microsoft Anna");

            oSpeaker.Volume = 100;

            if (bToFile)
            {
                oSpeaker.SetOutputToWaveFile("SoundByte.wav");
            }
            oSpeaker.Speak(sText);

            string msg;
            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                // Get information about supported audio formats.
                string AudioFormats = "";
                foreach (SpeechAudioFormatInfo fmt in synth.Voice.SupportedAudioFormats)
                {
                    AudioFormats += String.Format("{0}\n",
                    fmt.EncodingFormat.ToString());
                }

                // Write information about the voice to the console.
                msg = "Name:          " + synth.Voice.Name + "\n";
                msg += "Culture:       " + synth.Voice.Culture + "\n";
                msg += " Age:           " + synth.Voice.Age + "\n";
                msg += " Gender:        " + synth.Voice.Gender + "\n";
                msg += " Description:   " + synth.Voice.Description + "\n";
                msg += " ID:            " + synth.Voice.Id + "\n";
                if (synth.Voice.SupportedAudioFormats.Count != 0)
                {
                     msg += " Audio formats: " + AudioFormats + "\n";
                }
                else
                {
                     msg += " No supported audio formats found" + "\n";
                }

                // Get additional information about the voice.

                foreach (string key in synth.Voice.AdditionalInfo.Keys)
                {
                    msg += String.Format("  {0}: {1}\n",key, synth.Voice.AdditionalInfo[key]);
                }

                msg += " Additional Info - ";

            }
            oSpeaker.Dispose();
            oSpeaker = null;
            return msg;
        }
开发者ID:bfoote,项目名称:StudentInformation,代码行数:58,代码来源:CPerson.cs

示例4: VocalSynthesis

        public static void VocalSynthesis(string text, string culture, string filename, string voice)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();

            synth.SelectVoiceByHints(VoiceGender.Neutral, VoiceAge.NotSet, 1, new CultureInfo(culture));

            if (!string.IsNullOrEmpty(filename))
                synth.SetOutputToWaveFile(filename);
            if (!string.IsNullOrEmpty(voice))
                synth.SelectVoice(voice);

            synth.Speak(text);
        }
开发者ID:vincentCGI,项目名称:ensae_teaching_cs,代码行数:13,代码来源:Speech.cs

示例5: Main

        internal static void Main(string[] args)
        {
            try
            {
                synth = new SpeechSynthesizer();
                string textToSpeak = "";

                options = new OptionSet
            {
                { "v|voice=", "Use the specified {voice} (surround the name in quotes if it contains spaces).", x => { synth.SelectVoice(x); } },
                { "r|rate=", "Speak at the specified {rate} (0-20).", x => { SetRate(x); } },
                { "f|input-file=", "Speak the contents of {file.txt}.", x => { textToSpeak=File.ReadAllText(x); } },
                { "o|output-file=", "Save the audio to {file.wav}.", x => { synth.SetOutputToWaveFile(x); } },
                { "l|list-voices", "List available voices.", x => { ListVoices(); return; } },
                { "h|help", "Print this help message and exit.", x => { PrintHelpMessage(); return; } }
            };

                List<string> extra = options.Parse(args);

                if (textToSpeak == null || textToSpeak.Trim().Length == 0)
                {
                    if (extra.Count > 0)
                    {
                        textToSpeak = string.Join(" ", extra.ToArray());
                    }
                    else
                    {
                        textToSpeak = Console.In.ReadToEnd();
                    }
                }

                if (textToSpeak == null || textToSpeak.Trim().Length == 0)
                {
                    Console.WriteLine("Error: could not find text to speak.");
                    Console.WriteLine();
                    PrintHelpMessage();
                    return;
                }

                synth.Speak(textToSpeak);
            }
            catch (Exception x)
            {
                Console.WriteLine("Error: {0} - {1}", x.GetType().Name, x.Message);
                Console.WriteLine();
                PrintHelpMessage();
            }
        }
开发者ID:SaqibS,项目名称:say,代码行数:48,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            if( args.Length != 1)
            {
                Console.WriteLine("Usage: CreateWavFiles.exe file.csv" );
                return;
            }

            var dir = Path.GetDirectoryName(args[0]);
            CsvFile csv = new CsvFile(args[0]);
            dir = Path.Combine(dir,"output");
            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                Console.WriteLine("using voice :"+synth.Voice.Name);
                foreach (var item in synth.GetInstalledVoices())
                {
                   //.. Console.WriteLine(item.VoiceInfo.Name);
                }

                for (int i = 0; i < csv.Rows.Count; i++)
                {
                    // Set a value for the speaking rate. Slower to Faster (-10 to 10)
                    synth.Rate = -3;

                    // Configure the audio output.
                    string outputWavFileName = Path.Combine(dir, csv.Rows[i]["File Name"].ToString());
                    Console.WriteLine(outputWavFileName);
                    synth.SetOutputToWaveFile(outputWavFileName,
                      new SpeechAudioFormatInfo(8000, AudioBitsPerSample.Sixteen, AudioChannel.Mono));

              // Create a SoundPlayer instance to play output audio file.
                    //System.Media.SoundPlayer m_SoundPlayer = new System.Media.SoundPlayer(outputWavFileName);

                    // Build a prompt.
                    PromptBuilder builder = new PromptBuilder();
                    builder.AppendText(csv.Rows[i]["Text"].ToString());

                    // Speak the prompt.
                    synth.Speak(builder);
                    //m_SoundPlayer.Play();
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
开发者ID:usbr,项目名称:Pisces,代码行数:48,代码来源:CreateWavFiles.cs

示例7: SaveAsWav

        public static void SaveAsWav(PromptBuilder p, String directory)
        {
            bool hasFilePath = !String.IsNullOrWhiteSpace(directory);
            if (!hasFilePath)
            {
                // We check if there is text first, as
                // .SetOutputToWaveFile creates an empty WAV file
                // (even if nothing will be added to it.)
                return;
            }

            using (var synthesizer = new SpeechSynthesizer())
            {
                synthesizer.SetOutputToWaveFile(directory);
                synthesizer.Speak(p);
            }
        }
开发者ID:oswellchan,项目名称:PowerPointLabs,代码行数:17,代码来源:PromptToAudio.cs

示例8: Main

        static void Main(string[] args)
        {
            string voiceFileName = args[0];
            string voiceFileNamemp3 = voiceFileName.Replace(".wav", ".mp3");
            string voiceFilePath = args[1];
            string toBeVoiced = args[2];
            int rate = int.Parse(args[3]); ;
            string voice = args[4];

            voiceFileName = voiceFileName.Replace("~", " ");
            voiceFilePath = voiceFilePath.Replace("~", " ");
            toBeVoiced = toBeVoiced.Replace("~", " ");
            voice = voice.Replace("~", " ");

            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                //    // Output information about all of the installed voices. 
                //    Console.WriteLine("Installed voices -");
                foreach (InstalledVoice voice2 in synth.GetInstalledVoices())
                {
                    VoiceInfo info = voice2.VoiceInfo;
                    Console.WriteLine(" Voice Name: " + info.Name);
                }
            } 
            


            var reader = new SpeechSynthesizer();
            reader.Rate = rate;
            reader.SelectVoice(voice);

            try
            {
                reader.SetOutputToWaveFile(voiceFilePath + voiceFileName, new SpeechAudioFormatInfo(16025, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
                reader.Speak(toBeVoiced);
                reader.Dispose();
                WaveToMP3(voiceFilePath + voiceFileName, voiceFilePath + voiceFileNamemp3);
            }
            catch (Exception er)
            {
                string s1 = er.Message;
            }
        }
开发者ID:connecticutortho,项目名称:ct-ortho-repositories4,代码行数:45,代码来源:Program.cs

示例9: GetTTSAudio

        public Stream GetTTSAudio(string convertText)
        {
            if (convertText == null || convertText.Length > 10000)
                return null;

            var guid = Guid.NewGuid();
            var filePathStr = ConfigurationManager.AppSettings["tempWaveFileLocation"] +  "out" + guid.ToString() + ".wav";

            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                synth.SetOutputToWaveFile(filePathStr);
                synth.Speak(convertText);

                String headerInfo = "attachment; filename=out.wav";
                WebOperationContext.Current.OutgoingResponse.ContentType = "audio/x-wav";
                WebOperationContext.Current.OutgoingResponse.Headers["Content-Disposition"] = headerInfo;
            }

            return File.OpenRead(filePathStr);
        }
开发者ID:dgeller-OUHSC,项目名称:winTTSService,代码行数:20,代码来源:TTSService.cs

示例10: Main

        static void Main(string[] args)
        {
            var text = args.Length > 0 ? args[0] : "enter some text as first argument to this command";

            // Initialize a new instance of the SpeechSynthesizer.
            SpeechSynthesizer synth = new SpeechSynthesizer();

            // Configure the audio output.
            if (args.Length > 1)
            {
                var audioformat = new SpeechAudioFormatInfo(16000,AudioBitsPerSample.Sixteen, AudioChannel.Mono);
                synth.SetOutputToWaveFile(args[1], audioformat);
            }
            else
            {
                synth.SetOutputToDefaultAudioDevice();
            }

            // Speak a string.
            synth.Speak(text);
        }
开发者ID:benjamine,项目名称:SpeakDotNet,代码行数:21,代码来源:Program.cs

示例11: Main

 public static void Main(string[] args)
 {
     SpeechSynthesizer s = new SpeechSynthesizer();
     string lang = args[0].ToLower();
     if (lang.Equals("ja"))
         s.SelectVoice("Microsoft Server Speech Text to Speech Voice (ja-JP, Haruka)");
     else if (lang.Equals("en"))
         s.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-US, ZiraPro)");
     else if (lang.Equals("ko"))
         s.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, Heami)");
     else if (lang.Equals("zh"))
         s.SelectVoice("Microsoft Server Speech Text to Speech Voice (zh-CN, HuiHui)");
     else
         Environment.Exit(1);
     string textfile = args[1];
     string text = System.IO.File.ReadAllText(textfile, System.Text.Encoding.UTF8);
     string wavefile = args[2];
     s.Volume = 100;
     s.SetOutputToWaveFile(wavefile, new SpeechAudioFormatInfo(48000, AudioBitsPerSample.Sixteen, AudioChannel.Stereo));
     s.Speak(text);
     s.Dispose();
 }
开发者ID:sweemer,项目名称:tts,代码行数:22,代码来源:Program.cs

示例12: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show(this, "Write some text to start.", "Empty text", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            string[] texts = textBox1.Text.Split('\n');

            progressBar1.Value = 0;
            progressBar1.Maximum = texts.Length;

            for (int i = 0; i < texts.Length; i++)
            {
                var reader = new SpeechSynthesizer();
                //reader.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);
                reader.Rate = trackRate.Value;
                reader.Volume = trackVolume.Value;
                reader.SelectVoice(((VoiceInfo)cmbVoice.SelectedItem).Name);

                var bits = radio8Bits.Checked ? AudioBitsPerSample.Eight : AudioBitsPerSample.Sixteen;
                var channel = radioChannelMono.Checked ? AudioChannel.Mono : AudioChannel.Stereo;

                var format = new SpeechAudioFormatInfo(int.Parse(cmbSamples.Text), bits, channel);
                string filePath = Directory.GetCurrentDirectory() + @"\Output\";
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                reader.SetOutputToWaveFile(Directory.GetCurrentDirectory() + @"\Output\" + GetAudioFileName(texts[i]), format);
                reader.Speak(GetAudioText(texts[i]));
                progressBar1.Value++;
                reader.Dispose();
            }
            MessageBox.Show(this, "All done. Check .wav files on 'Output' folder.", "Finish", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
开发者ID:rhpa23,项目名称:TTSrecorder,代码行数:37,代码来源:Form1.cs

示例13: Generate

        public void Generate(List<string> p_aryNames, List<string> p_aryLines, string p_strPath, int p_nRate, AudioBitsPerSample p_samples, AudioChannel p_channels)
        {
            SpeechAudioFormatInfo t_audioFormatInfo = new SpeechAudioFormatInfo(p_nRate, p_samples, p_channels);
            SpeechSynthesizer t_synth = new SpeechSynthesizer();

            progressBar1.Maximum = p_aryLines.Count;
            progressBar1.Step = 1;

            label1.Text = progressBar1.Step + "/" + p_aryNames.Count;

            for (int t_i = 0; t_i < p_aryNames.Count; ++t_i)
            {
                t_synth.SetOutputToWaveFile(p_strPath + "\\" + p_aryNames[t_i] + ".wav");
                t_synth.Speak(p_aryLines[t_i]);

                label1.Text = (t_i + 1) + "/" + p_aryLines.Count;
                progressBar1.PerformStep();
                progressBar1.Refresh();
            }

            t_synth.Dispose();

            Close();
        }
开发者ID:andrewauclair,项目名称:Voice-Generation,代码行数:24,代码来源:Progress.cs

示例14: CreateFirstVoiceFile

        public void CreateFirstVoiceFile(VoicingParameters voicingParameters, string toBeVoiced)
        {
            string fileName = string.Empty;
            string sequence = string.Empty;
            string liveOrVoice = string.Empty;
            SpeechSynthesizer reader;
            fileName = "first.wav";

            reader = new SpeechSynthesizer();
            //  reader.
            // reader.Volume = 200;
            // reader.Rate = 200;

            reader.Rate = voicingParameters.Rate;
            reader.SelectVoice(voicingParameters.VoiceName);
            try
            {
                //reader.SetOutputToWaveFile(voiceFilePath + fileName, new SpeechAudioFormatInfo(11025, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
                reader.SetOutputToWaveFile(voicingParameters.VoiceFilePath + fileName, new SpeechAudioFormatInfo(16025, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
                //********************************************************************************
                reader.Speak(toBeVoiced);
            }
            catch (Exception er)
            {
                string s1 = er.Message;
            }
        }
开发者ID:connecticutortho,项目名称:ct-ortho-repositories4,代码行数:27,代码来源:CreateVoiceFiles.cs

示例15: CreateVoiceFileSample

        public void CreateVoiceFileSample(VoicingParameters voicingParameters, string toBeVoiced)
        {
            string fileName = string.Empty;
            fileName = voicingParameters.VoiceFileName;

            readerSample = new SpeechSynthesizer();
            readerSample.Rate = voicingParameters.Rate;

            readerSample.SelectVoice(voicingParameters.VoiceName);
            try
            {
                readerSample.SetOutputToWaveFile(voicingParameters.VoiceFilePath + fileName, new SpeechAudioFormatInfo(16025, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
                readerSample.Speak(toBeVoiced);
            }
            catch (Exception er)
            {
                Log.LogMessage(er.ToString());
            }
        }
开发者ID:connecticutortho,项目名称:ct-ortho-repositories4,代码行数:19,代码来源:CreateVoiceFiles.cs


注:本文中的SpeechSynthesizer.SetOutputToWaveFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。