Ahmad
Ahmad

Reputation: 9668

Audio position in SpeakProgress event is not correct for "Microsoft Anna" voice

In a text to speech application by c# I use SpeechSynthesizer class, it has an event named SpeakProgress which is fired for every spoken word. But for some voices including "Microsoft Anna" the parameter e.AudioPosition is not synchronized with the output audio stream, and the audio stream is played faster than what AuidoPosition indicates.

void reader_SpeakProgress(object sender, SpeakProgressEventArgs e)
{
      Console.Write(e.AudioPosition + "");
}

I thought maybe the problem is the bitrate and the WaveStream as the output which I use as the following.

  FileStream AudioStream 
    = new FileStream(fname, FileMode.Create, FileAccess.Write); 
   reader.SetOutputToWaveStream(AudioStream);

I tried

var formats = CurVoice.VoiceInfo.SupportedAudioFormats;
reader.SetOutputToAudioStream(AudioStream, formats[0]);

But the problem now is that the output file is not played. Do you have any suggestions for why the voice is not synch and why my solution has no playable output audio?

Upvotes: 0

Views: 305

Answers (1)

Ahmad
Ahmad

Reputation: 9668

As I have guessed the problem was related to bitrate, to enforce the audio format I used an alternative method named SetOutputToWaveFile

var formats = CurVoice.VoiceInfo.SupportedAudioFormats;
reader.SetOutputToWaveFile(fname, formats[0]);

with the code above, the audio output is playable and also the synching problem resolved!

Upvotes: 0

Related Questions