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


C# SpeechSynthesizer.SetOutputToWaveStream方法代码示例

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


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

示例1: TestPhonemes

        public void TestPhonemes()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                synth.SetOutputToWaveStream(stream);

                synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>This is your <phoneme alphabet=\"ipa\" ph=\"leɪkɒn\">Lakon</phoneme>.</s></speak>");

                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈdɛltə\">delta</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"bliːiː\">Bleae</phoneme> <phoneme alphabet=\"ipa\" ph=\"θuːə\">Thua</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the Amnemoi system.</s></speak>");
                //synth.Speak("You are travelling to the Barnard's Star system.");
                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new WaveFileReader(stream);

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(source);
                soundOut.Play();

                waitHandle.WaitOne();
                soundOut.Dispose();
                source.Dispose();
            }
        }
开发者ID:cmdrmcdonald,项目名称:EliteDangerousDataProvider,代码行数:30,代码来源:SpeechTests.cs

示例2: Main

        static void Main()
        {

            IList<string> args = new List<string>();
            string s = Console.ReadLine();
            while(!string.IsNullOrEmpty(s)){
                args.Add(s);
                s = Console.ReadLine();
            }

            foreach (string word in args)
            //Create wav file for each sound
            {
                using (FileStream f = new FileStream(word + ".wav", FileMode.Create))
                {
                    using (SpeechSynthesizer speak = new SpeechSynthesizer())
                    {
                        speak.SetOutputToWaveStream(f);
                        speak.Speak(word);
                    }
                }
                //Create phoneme text file for each word                
                using (FileStream f = new FileStream(word + ".txt", FileMode.Create))
                {
                    //call function to extract the phoneme
                    ExtractPhoneme2 extract = new ExtractPhoneme2();
                    string phoneme = extract.getPhoneme(word);

                    //Encode the phoneme and write  to file
                    Byte[] info = new UTF8Encoding(true).GetBytes(phoneme + "\n");                    
                    f.Write(info, 0, info.Length);
                }
            }
        }
开发者ID:alulam,项目名称:NaturalSpeech,代码行数:34,代码来源:Program.cs

示例3: SpeechToWavBytes

        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="speechText"></param>
        /// <returns></returns>
        public byte[] SpeechToWavBytes(string speechText)
        {
            if(speechText == null) throw new ArgumentNullException("speechText");
            byte[] result = new byte[] {};

            if(IsSupported) {
                using(MemoryStream memoryStream = new MemoryStream()) {
                    using(SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer() { Rate = -3 }) {
                        var configuration = Factory.Singleton.Resolve<IConfigurationStorage>().Singleton.Load();

                        speechSynthesizer.Rate = configuration.AudioSettings.VoiceRate;
                        string defaultVoice = speechSynthesizer.Voice.Name;
                        try {
                            speechSynthesizer.SelectVoice(configuration.AudioSettings.VoiceName);
                        } catch(Exception ex) {
                            Debug.WriteLine(String.Format("Audio.SpeechToWavBytes caught exception {0}", ex.ToString()));
                            speechSynthesizer.SelectVoice(defaultVoice);
                        }

                        speechSynthesizer.SetOutputToWaveStream(memoryStream);
                        speechSynthesizer.Speak(speechText);
                    }

                    memoryStream.Flush();
                    result = memoryStream.ToArray();
                }
            }

            return result;
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:35,代码来源:Audio.cs

示例4: WriteToStream

 public override void WriteToStream(object instance, System.IO.Stream stream, System.Net.Http.HttpRequestMessage request)
 {
     var text = instance as string;
     if (text == null) return;
     using(var synth = new SpeechSynthesizer())
     {
         synth.SetOutputToWaveStream(stream);
         //synth.Rate -= 10;
         synth.Speak("current time is "+text);
     }
 }
开发者ID:prompt,项目名称:preprompt-wcf-http,代码行数:11,代码来源:WaveFromTextMediaProcessor.cs

示例5: OnWriteToStream

 public override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
 {
     var s = value as string;
     if (s == null) return;
     using (var synth = new SpeechSynthesizer())
     {
         var ms = new MemoryStream();
         synth.SetOutputToWaveStream(ms);
         //synth.Rate -= 10;
         synth.Speak("current time is " + s);
         ms.Seek(0, SeekOrigin.Begin);
         ms.CopyTo(stream);
     }
 }
开发者ID:pmhsfelix,项目名称:ISELTech11,代码行数:14,代码来源:WaveFromTextFormatter.cs

示例6: WaveContent

 public WaveContent(string text)
 {
     _stream = new Lazy<Stream>(() =>
     {
         using (var synth = new SpeechSynthesizer())
         {
             var ms = new MemoryStream();
             synth.SetOutputToWaveStream(ms);
             synth.Speak(text);
             ms.Seek(0, SeekOrigin.Begin);
             return ms;
         }
     });
     Headers.ContentType = new MediaTypeHeaderValue("audio/x-wav");
 }
开发者ID:pmhsfelix,项目名称:ndc-london-13-web-api,代码行数:15,代码来源:WaveContent.cs

示例7: OnWriteToStreamAsync

 protected override Task OnWriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, TransportContext transportContext)
 {
     return SyncTask.From(() =>
                              {
                                  var s = value as string;
                                  if (s == null) return;
                                  using (var synth = new SpeechSynthesizer())
                                  {
                                      var ms = new MemoryStream();
                                      synth.SetOutputToWaveStream(ms);
                                      //synth.Rate -= 10;
                                      synth.Speak("response is "+s);
                                      ms.Seek(0, SeekOrigin.Begin);
                                      ms.CopyTo(stream);
                                  }
                                  stream.Close();
                              });
 }
开发者ID:pmhsfelix,项目名称:presentation-netponto-webapi,代码行数:18,代码来源:WaveFromTextFormatter.cs

示例8: GETAudio

        public void GETAudio()
        {
            string AlarmText = GetAlarmData();
            SpeechSynthesizer ss = new SpeechSynthesizer();

            MemoryStream ms = new MemoryStream();
            //string name = ss.GetInstalledVoices()[1].VoiceInfo.Name;
            //ss.SelectVoice(name);
            byte[] b = null;
            try
            {
                if (!String.IsNullOrEmpty(AlarmText))
                {
                    //VoiceInfo tts;
                    //tts = ss.GetInstalledVoices()[0].VoiceInfo;
                    ss.SetOutputToWaveStream(ms);
                    ss.SelectVoice("Microsoft Mike");
                    ss.Speak(AlarmText);
                    b = ms.ToArray();

                    //SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                    //SpVoice voice = new SpVoice();
                    //voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(3);
                    //SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;

                    //SpFileStream SpFileStream = new SpFileStream();
                    //SpFileStream.Open(@"C:\test.wav", SpFileMode, false);
                    //voice.AudioOutputStream = SpFileStream;//设定voice的输出为Stream
                    //voice.Speak(AlarmText, flag);
                    //voice.WaitUntilDone(Timeout.Infinite);//Using System.Threading;

                    //SpFileStream.Close();
                }
            }
            catch (Exception ex)
            {
                b = System.Text.Encoding.Default.GetBytes(ex.Message.ToString());
            }
            finally
            {
                ms.Dispose();
            }
            //return b;
        }
开发者ID:SaintLoong,项目名称:ZiChang_SafetyNetworking,代码行数:44,代码来源:GetAlarm.cs

示例9: TextToWavStream

 public byte[] TextToWavStream(string AlarmText)
 {
     SpeechSynthesizer ss = new SpeechSynthesizer();
     MemoryStream ms = new MemoryStream();
     try
     {
         ss.SetOutputToWaveStream(ms);
         ss.Speak(AlarmText);
     }
     catch (InvalidOperationException)
     {
         AlarmText = "语言包发生故障。";
     }
     catch (ArgumentException)
     {
         AlarmText = "语言包发生故障。";
     }
     return ms.ToArray();
 }
开发者ID:SaintLoong,项目名称:ZiChang_SafetyNetworking,代码行数:19,代码来源:GetAlamer.svc.cs

示例10: TestExtendedSource

        public void TestExtendedSource()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                synth.SetOutputToWaveStream(stream);
                synth.Speak("Test.");
                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new ExtendedDurationWaveSource(new WaveFileReader(stream), 2000).AppendSource(x => new DmoWavesReverbEffect(x) { ReverbMix = -10 });

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(source);
                soundOut.Play();

                waitHandle.WaitOne();
                soundOut.Dispose();
                source.Dispose();
            }
        }
开发者ID:Handfeger,项目名称:EliteDangerousDataProvider,代码行数:24,代码来源:SpeechTests.cs

示例11: TestSpeech

 public void TestSpeech()
 {
     SpeechSynthesizer synth = new SpeechSynthesizer();
     using (MemoryStream stream = new MemoryStream())
     {
         synth.SetOutputToWaveStream(stream);
         synth.Speak("This is a test.");
         stream.Seek(0, SeekOrigin.Begin);
         IWaveSource source = new WaveFileReader(stream);
         EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
         var soundOut = new WasapiOut();
         DmoEchoEffect echoSource = new DmoEchoEffect(source);
         soundOut.Initialize(echoSource);
         soundOut.Stopped += (s, e) => waitHandle.Set();
         soundOut.Play();
         waitHandle.WaitOne();
         soundOut.Dispose();
         source.Dispose();
     }
 }
开发者ID:cmdrmcdonald,项目名称:EliteDangerousDataProvider,代码行数:20,代码来源:SpeechTests.cs

示例12: TestFlatten

        public void TestFlatten()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                synth.SetOutputToWaveStream(stream);
                synth.Speak("This is a test for flattening");
                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new WaveFileReader(stream);
                Equalizer equalizer = Equalizer.Create10BandEqualizer(source);
                equalizer.SampleFilters[0].SetGain(-9.6f);
                equalizer.SampleFilters[1].SetGain(-9.6f);
                equalizer.SampleFilters[2].SetGain(-9.6f);
                equalizer.SampleFilters[3].SetGain(-3.9f);
                equalizer.SampleFilters[4].SetGain(2.4f);
                equalizer.SampleFilters[5].SetGain(11.1f);
                equalizer.SampleFilters[6].SetGain(15.9f);
                equalizer.SampleFilters[7].SetGain(15.9f);
                equalizer.SampleFilters[8].SetGain(15.9f);
                equalizer.SampleFilters[9].SetGain(16.7f);

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(equalizer.ToWaveSource());
                soundOut.Play();

                waitHandle.WaitOne();

                soundOut.Dispose();
                equalizer.Dispose();
                source.Dispose();
            }
        }
开发者ID:cmdrmcdonald,项目名称:EliteDangerousDataProvider,代码行数:37,代码来源:SpeechTests2.cs

示例13: Button_Click_2

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            this.sensor.DepthFrameReady += this.SensorDepthFrameReady;
            if (Globals.value == "0")
            {

                // Initialize a new instance of the speech synthesizer.
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                using (MemoryStream stream = new MemoryStream())
                {

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

                    // Configure the synthesizer to output to an audio stream.
                    synth.SetOutputToWaveStream(streamAudio);

                    // Speak a phrase.
                    synth.Speak("stop!! obstacle detected.");

                    streamAudio.Position = 0;
                    m_SoundPlayer.Stream = streamAudio;
                    m_SoundPlayer.Play();

                    // Set the synthesizer output to null to release the stream.
                    synth.SetOutputToNull();
                    System.Windows.Forms.MessageBox.Show("press ok");
                    Globals.value = "1";
                    // Insert code to persist or process the stream contents here.
                }

            }
        }
开发者ID:nitinrgupta,项目名称:BlindNav,代码行数:34,代码来源:MainWindow.xaml.cs

示例14: TestDistortion

        public void TestDistortion()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    Console.WriteLine(voice.VoiceInfo.Name);
                }

                synth.SetOutputToWaveStream(stream);
                synth.Speak("Anaconda golf foxtrot lima one niner six eight requesting docking.");
                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new WaveFileReader(stream);
                DmoDistortionEffect distortedSource = new DmoDistortionEffect(source);
                distortedSource.Edge = 10;
                distortedSource.PreLowpassCutoff = 4800;

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(distortedSource);
                soundOut.Play();

                waitHandle.WaitOne();

                soundOut.Dispose();
                distortedSource.Dispose();
                source.Dispose();
            }
        }
开发者ID:cmdrmcdonald,项目名称:EliteDangerousDataProvider,代码行数:34,代码来源:SpeechTests2.cs

示例15: TestRandomVoice

        public void TestRandomVoice()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            List<InstalledVoice> availableVoices = new List<InstalledVoice>();
            foreach (InstalledVoice voice in new SpeechSynthesizer().GetInstalledVoices())
            {
                if (voice.Enabled == true && voice.VoiceInfo.Culture.TwoLetterISOLanguageName == "en" && (voice.VoiceInfo.Name.StartsWith("IVONA") || voice.VoiceInfo.Name.StartsWith("CereVoice") || voice.VoiceInfo.Name == "Microsoft Anna"))
                {
                    availableVoices.Add(voice);
                }
            }
            foreach (InstalledVoice availableVoice in availableVoices)
            {
                Console.WriteLine(availableVoice.VoiceInfo.Name);
            }

            for (int i = 0; i < 10; i++)
            {
                using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    string selectedVoice = availableVoices.OrderBy(x => Guid.NewGuid()).FirstOrDefault().VoiceInfo.Name;
                    Console.WriteLine("Selected voice is " + selectedVoice);
                    synth.SelectVoice(selectedVoice);

                    synth.SetOutputToWaveStream(stream);
                    //synth.Speak("Anaconda golf foxtrot lima one niner six eight requesting docking.");
                    synth.Speak("Anaconda.");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource source = new WaveFileReader(stream);

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(source);
                    soundOut.Play();

                    waitHandle.WaitOne();

                    soundOut.Dispose();
                    source.Dispose();
                }
            }
        }
开发者ID:cmdrmcdonald,项目名称:EliteDangerousDataProvider,代码行数:46,代码来源:SpeechTests2.cs


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