本文整理汇总了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();
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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");
}
示例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();
});
}
示例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;
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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.
}
}
}
示例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();
}
}
示例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();
}
}
}