Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
0
Reply
NAudio waveout stops after half 1 second
Oliver Link
Aug 22 2017 3:30 PM
228
Reply
Hey im using NAudio to playback SpeechSynthesizer with some strange result.
There are to different outputs the first works perfect the second is exactly the same just with an other input text but the playback stops after half 1 second and the PlaybackState never leave PlaybackState.Playing. This happens also if both inputs are the same.
but lets have a look at my code:
waveOut =
new
WaveOut();
if
(SayText ==
""
)
{
MemoryStream stream =
new
MemoryStream();
try
{
IWaveProvider provider =
null
;
using
(var synth =
new
SpeechSynthesizer())
{
synth.SetOutputToAudioStream(stream,
new
SpeechAudioFormatInfo(44100, AudioBitsPerSample.Sixteen, AudioChannel.Stereo));
lock
(textoutput)
{
synth.Speak(textoutput); // Example:
textoutput = Hallo
}
stream.Seek(0, SeekOrigin.Begin);
provider =
new
RawSourceWaveStream(stream,
new
WaveFormat(44100, 16, 2));
}
waveOut.DeviceNumber = getDevices(
"tts"
);
// getDevices returns 1
waveOut.Init(provider);
waveOut.Play();
do
{}
while
(waveOut.PlaybackState == PlaybackState.Playing);
waveOut.Dispose();
}
catch
(System.Exception e)
{
MessageBox.Show(
"Error playing sound: "
+ e.Message);
}
}
// THIS PART MAKE SOME PROBLEMS
else
{
MemoryStream stream =
new
MemoryStream();
try
{
IWaveProvider provider =
null
;
using
(var synth =
new
SpeechSynthesizer())
{
synth.SetOutputToAudioStream(stream,
new
SpeechAudioFormatInfo(44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
lock
(SayText)
{
synth.Speak(SayText);
// Example:
SayText
= Hallo
}
stream.Seek(0, SeekOrigin.Begin);
provider =
new
RawSourceWaveStream(stream,
new
WaveFormat(44100, 16, 1));
}
waveOut.DeviceNumber = getDevices(
"say"
); // getDevices returns 1
waveOut.Init(provider);
waveOut.Play(); // after that step the waveout stops directly and the following loop never ends because
waveOut.PlaybackState is always Playing
do
{}
while
(waveOut.PlaybackState == PlaybackState.Playing);
waveOut.Dispose();
}
catch
(System.Exception e)
{
MessageBox.Show(
"Error playing sound: "
+ e.Message);
}
SayText =
""
;
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
Eval and Bind methods in asp.net
how to move cursor from one to another textbox click on tab