TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Oliver Link
NA
2
1.8k
NAudio waveout stops after half 1 second
Aug 22 2017 3:30 PM
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 =
""
;
}
Reply
Answers (
0
)
Eval and Bind methods in asp.net
how to move cursor from one to another textbox click on tab