I have a simple code generating a wave file using TTS and then playing it:
public void TestSpeech() { SpeechSynthesizer synth = new SpeechSynthesizer(); using (MemoryStream stream = new MemoryStream()) { synth.SetOutputToWaveStream(stream); synth.Speak("Hello world"); stream.Seek(0, SeekOrigin.Begin); IWaveSource source = new WaveFileReader(stream); EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); var soundOut = new WasapiOut(); soundOut.Initialize(source); soundOut.Stopped += (s, e) => waitHandle.Set(); soundOut.Play(); waitHandle.WaitOne(); soundOut.Dispose(); source.Dispose(); } }
Everything works fine, but I want to know, before I start playing the wave file, how long it will last. Is there a way to calculate this, or is it available somewhere?
If it is available somewhere, how is it calculated? I assume this is due to the amount of data in the stream, but how?
source share