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


C# SpeechSynthesizer.Dispose方法代码示例

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


在下文中一共展示了SpeechSynthesizer.Dispose方法的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: SpeakMessage

        public void SpeakMessage(AudioVideoFlow flow, string message)
        {
            try
            {
                SpeechSynthesizer synth = new SpeechSynthesizer();
                SpeechAudioFormatInfo formatInfo = new SpeechAudioFormatInfo(16000, AudioBitsPerSample.Sixteen, Microsoft.Speech.AudioFormat.AudioChannel.Mono);
                SpeechSynthesisConnector connector = new SpeechSynthesisConnector();

                synth.SetOutputToAudioStream(connector.Stream, formatInfo);

                connector.AttachFlow(flow);
                connector.Start();

                synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(
                    (sender, args) =>
                    {
                        connector.Stop();
                        synth.Dispose();
                    });

                synth.SpeakAsync(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to play the message. {0}", ex);
            }

        }
开发者ID:hhqqnu,项目名称:MSLyncProjects,代码行数:28,代码来源:AVCallHelper.cs

示例3: ReadOutLoud

        public async void ReadOutLoud()
        {
            IEnumerable<VoiceInformation> voices = from voice in InstalledVoices.All
                                                   where voice.Language == "en-US" && voice.Gender == VoiceGender.Female
                                                   select voice;

            // Set the voice as identified by the query.
            //try
            //{
            //    if(voices.Count() > 0)
            //        synth.SetVoice(voices.ElementAt(0));
            //}
            //catch
            //{

            //}

            ICategoryRepository categoryRepository = new XmlCategoryRepository();

            foreach (string id in categoryIds)
            {
                CategoryData category = categoryRepository.GetCategoryById(Convert.ToInt32(id));
                //this.CategoryName.Text = category.Name;
                Uri imageUri = new Uri(category.Image, UriKind.Relative);
                var bitmap = new BitmapImage(imageUri);
                this.CategoryImage.Source = bitmap;
                RssParser rssParser = new RssParser();
                Uri feedUri = new Uri(category.Feed, UriKind.Relative);
                StreamResourceInfo sri = Application.GetResourceStream(feedUri);
                rssParser.initializeLocal(sri.Stream);
                List<NewsItem> topStories = rssParser.getTopStories();
                foreach (NewsItem newsItem in topStories)
                {
                    try
                    {
                        synth = new SpeechSynthesizer();
                        if (voices.Count() > 0)
                            synth.SetVoice(voices.ElementAt(0));
                        if (String.IsNullOrEmpty(newsItem.description))
                            continue;
                        this.CategoryName.Text = newsItem.title;
                        this.SummaryBlock.Text = newsItem.description;
                        string textToRead = newsItem.title + ".\n" + newsItem.source + " reports, " + newsItem.description + "\n\n";
                        await synth.SpeakTextAsync(textToRead);
                        synth.Dispose();
                    }
                    catch
                    {

                    }
                }
            }
        }
开发者ID:Hitchhikrr,项目名称:Hackathon,代码行数:53,代码来源:ContentDisplayPage.xaml.cs

示例4: 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

示例5: _Speak

        private static async void _Speak(string text)
        {
            MediaElement mediaElement = new MediaElement();
            SpeechSynthesizer synth = new SpeechSynthesizer();


            foreach (VoiceInformation voice in SpeechSynthesizer.AllVoices)
            {
                Debug.WriteLine(voice.DisplayName + ", " + voice.Description);
            }

            // Initialize a new instance of the SpeechSynthesizer. 
            SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(text);

            // Send the stream to the media object. 
            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();

            mediaElement.Stop();
            synth.Dispose();
        }
开发者ID:tyeth,项目名称:Christmas-List,代码行数:21,代码来源:TextToSpeech.cs

示例6: 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

示例7: 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

示例8: 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

示例9: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            IList<VoiceInfo> voiceInfos = new List<VoiceInfo>();
            var reader = new SpeechSynthesizer();

            var installedVoices = reader.GetInstalledVoices();
            if (installedVoices.Count == 0)
            {
                MessageBox.Show(this,
                    "Your system don't have a 'Text to Speech' to make this work. Try install one for continue.",
                    "Finish", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                foreach (InstalledVoice voice in installedVoices)
                {
                    voiceInfos.Add(voice.VoiceInfo);
                }
                cmbVoice.DataSource = voiceInfos;
                cmbVoice.DisplayMember = "Name";
                cmbVoice.ValueMember = "Id";
            }
            reader.Dispose();
        }
开发者ID:rhpa23,项目名称:TTSrecorder,代码行数:25,代码来源:Form1.cs

示例10: btnStart_Click

        /// <summary>
        /// Starts live video streaming, Pauses it to detect faces, Resumes it 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.Speak("Welcome to the magic mirror");
            synth.Dispose();

            //MessageBox.Show("Câmera selecionada");
            if (capture != null)
            {
                if (btnStart.Text == "Extrair Rosto")
                {  //if camera is getting frames then pause the capture and set button Text to
                    // "Resume" for resuming capture
                    btnStart.Text = "Resumir Imagem"; //

                    //Pause the live streaming video
                    Application.Idle -= ProcessFrame;

                    //Call face detection
                    DetectFaces();
                }
                else
                {
                    //if camera is NOT getting frames then start the capture and set button
                    // Text to "Pause" for pausing capture
                    btnStart.Text = "Extrair Rosto";
                    Application.Idle += ProcessFrame;
                }
            }
        }
开发者ID:kaueelima,项目名称:TCC-Oficial,代码行数:34,代码来源:TrainingSetEditor.cs

示例11: Say

 public static void Say(string str, int rate)
 {
     SpeechSynthesizer synthesizer = new SpeechSynthesizer();
     synthesizer.Volume = 100;
     synthesizer.Rate = rate;     // -10...10
     synthesizer.Speak(str);
     if (synthesizer.State != SynthesizerState.Speaking)
     {
         synthesizer.Dispose();
     }
 }
开发者ID:PixelZerg,项目名称:IlluminatiConfirmed,代码行数:11,代码来源:Program.cs

示例12: Show


//.........这里部分代码省略.........
                   long life = gm.lifeMonitor.Mode(await gm.lifeMonitor.ReadDataAsync());
                   long unit = gm.unitMonitor.Mode(await gm.unitMonitor.ReadDataAsync());

                   gm.dataGiveIn.SendData(CombineAndSplitSign.Combine(BallanceOnline.Const.ClientAndServerSign.Client, BallanceOnline.Const.SocketSign.GameDataTurnIn, mark.ToString() + "," + life.ToString() + "," + unit.ToString()));

                   //如果有相同情况出现,提醒警告
                   if (overCount == false) {
                       if (previousMark == mark) {
                           similarityCount--;
                           //检查超限
                           if (similarityCount < 0) {
                               uiTimer.Dispatcher.Invoke(() => { uiTimer.Text = ""; });
                               uiTimerContainer.Dispatcher.Invoke(() => { uiTimerContainer.Visibility = Visibility.Collapsed; });
                               overCount = true;
                           } else {
                               uiTimer.Dispatcher.Invoke(() => { uiTimer.Text = similarityCount.ToString(); });
                               uiTimerContainer.Dispatcher.Invoke(() => { uiTimerContainer.Visibility = Visibility.Visible; });
                           }

                       } else {
                           if (similarityCount != 20) {
                               similarityCount = 20;
                               uiTimer.Dispatcher.Invoke(() => { uiTimer.Text = ""; });
                               uiTimerContainer.Dispatcher.Invoke(() => { uiTimerContainer.Visibility = Visibility.Collapsed; });
                           }
                       }
                   }

                   previousMark = mark;

                   Thread.Sleep(1000);

               }

               speakStart.Dispose();

               //结束

               });

            //显示成就的操作
            Task.Run(() =>
            {
                while (true) {
                    if (stopShowPrize == true) { break; }
                    if (prizeLine.Count == 0) { Thread.Sleep(500); continue; }

                    //展示
                    var cache = prizeLine.Dequeue();
                    string sayWord = "";
                    string showWord = cache.PlayerName + " ";

                    switch (cache.PrizeName) {
                        case GamePrize.FirstBlood:
                            showWord += GamePrize.FirstBloodShow;
                            sayWord = GamePrize.FirstBloodSpeech;
                            break;
                        case GamePrize.Reborn:
                            showWord += GamePrize.RebornShow;
                            sayWord = GamePrize.RebornSpeech;
                            break;
                        case GamePrize.Silence:
                            showWord += GamePrize.SilenceShow;
                            sayWord = GamePrize.SilenceSpeech;
                            break;
                        case GamePrize.Time:
                            showWord += GamePrize.TimeShow;
                            sayWord = GamePrize.TimeSpeech;
                            break;
                        case GamePrize.Ace:
                            showWord += GamePrize.AceShow;
                            sayWord = GamePrize.AceSpeech;
                            break;
                    }

                    //show
                    uiNoticeText.Dispatcher.Invoke(() =>
                    {
                        uiNoticeText.Text = showWord;
                    });
                    uiNotice.Dispatcher.Invoke(() =>
                    {
                        uiNotice.Visibility = Visibility.Visible;
                    });

                    //say
                    SpeechSynthesizer speak = new SpeechSynthesizer();
                    speak.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
                    speak.Speak(sayWord);
                    speak.Dispose();

                    //hide
                    uiNotice.Dispatcher.Invoke(() =>
                    {
                        uiNotice.Visibility = Visibility.Visible;
                    });
                }

            });
        }
开发者ID:yyc12345,项目名称:BallanceToolsBox,代码行数:101,代码来源:PlayNow.xaml.cs

示例13: Play

 private void Play(object text)
 {
     SpeechSynthesizer synth = new SpeechSynthesizer();
     PromptBuilder builder = new PromptBuilder(new System.Globalization.CultureInfo("zh-CN"));
     synth.SetOutputToDefaultAudioDevice();
     if (SelectVoice.Items.Count > 0)
     {
         synth.SelectVoice(SelectVoice.SelectedItem.ToString()); //语音选择
     }
     synth.Rate = Convert.ToInt32(voiceRate.Text);//语速
     builder.AppendText(text.ToString());
     synth.Speak(builder);
     synth.Dispose();
 }
开发者ID:tonm04,项目名称:SpVoice,代码行数:14,代码来源:Form1.cs

示例14: textToAudioStream

        private static Stream textToAudioStream(string textToConvert, string voiceName, int voiceRate, BackgroundWorker worker)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SpeakProgress += delegate(object sender, SpeakProgressEventArgs e)
            { synth_SpeakProgress(sender, e, worker, textToConvert.Length); };
            Stream audioStream = new MemoryStream();
            synth.SetOutputToWaveStream(audioStream); // set to wave file stream
            synth.SelectVoice(voiceName);
            synth.Rate = voiceRate;
            synth.Speak(textToConvert); // send data to stream
            synth.Dispose();

            audioStream.Position = 0;   // reset position for audio stream so it can be read

            return audioStream;
        }
开发者ID:sorvis,项目名称:Fast-Script,代码行数:16,代码来源:AudioFileMaker.cs

示例15: Speech

 private async void Speech(string text)
 {
     talk = new SpeechSynthesizer();
     try
     {
         await talk.SpeakTextAsync(text);
         talk.Dispose();
     }
     catch (Exception)
     {
         MessageBox.Show("Error when trying to use Text to speech", "Error", MessageBoxButton.OK);
         talk.Dispose();
     }
 }
开发者ID:BrianLima,项目名称:CortanaQuick,代码行数:14,代码来源:MainPage.xaml.cs


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