I am trying to write the output of SpeechSynthesizer
to a .wav file. If the synthesis is completed, everything works well and the output file is playable;
AudioStream = new FileStream(CurAudioFile, FileMode.Create);
reader.SetOutputToWaveStream(AudioStream);
reader.SpeakAsynch(myPromptBuilder);
But if I cancel the synthesis to the file through the following code (because the process is too long and I may want to cancel it) the output file produces no sound! (the produced file is not zero in size but nothing is played).
// On Cancel Button Clicked
reader.SpeakAsyncCancelAll();
while (reader.State == SynthesizerState.Speaking)
{
Application.DoEvents();
}
// reader.SetOutputToNull();
AudioStream.Close();
I look for a solution in which I can cancel the audio generation, but the audio file can be played to the portion before it was canceled.
Is there any way I can achieve this?