private void synthesizer_SpeakProgress(object sender, SpeakProgressEventArgs e) { string t = string.Empty; int c = _textToRead.Length; string token = string.Empty; int charCount = e.Text.Length; for (int i = _charPos; i < c; i++) { t = _textToRead.Substring(i, charCount); if (e.Text == t) { if (i - _charPos > 0 && _progress.Count > 0) { token = _textToRead.Substring(_charPos, i - _charPos); _progress[_progress.Count - 1].Text += token; } //t = _textToRead.Substring(i, e.CharacterCount); _charPos = i + charCount; break; } } //Fix negative timespan issue TimeSpan audioPos = e.AudioPosition; if (e.AudioPosition.Ticks < 0) { if (_lastPositiveTime == null) { _lastPositiveTime = _progress[_progress.Count - 1].AudioPosition; } audioPos = new TimeSpan(2 * _lastPositiveTime.Value.Ticks + e.AudioPosition.Ticks); } var prog = new SpeakProgress() { AudioPosition = audioPos, CharacterCount = charCount, CharacterPosition = e.CharacterPosition, Text = t }; _progress.Add(prog); if (100 * _charPos / c > _percentage) { _percentage = 100 * _charPos / c; Console.Write(string.Format("\r{0:d3}%", _percentage)); } //s = s + e.Text + Environment.NewLine; //Console.WriteLine("SpeakProgress: AudioPosition=" + e.AudioPosition + ",\tCharacterPosition=" + e.CharacterPosition + ",\tCharacterCount=" + e.CharacterCount + ",\tText=" + e.Text); //_s = _s + "SpeakProgress: AudioPosition=" + e.AudioPosition + ",\tCharacterPosition=" + e.CharacterPosition + ",\tCharacterCount=" + e.CharacterCount + ",\tText=" + e.Text + Environment.NewLine; }
private SpeakProgress EstimateEndTime(long AudioPositionTicks, long CharacterPosition, int CharacterCount) { var p = new SpeakProgress(); //var ticks = progress[lastIdx].AudioPosition.Ticks; //var txtCount = progress[lastIdx].CharacterPosition; var ticksByChar = Convert.ToInt64(AudioPositionTicks / CharacterPosition); p.AudioPosition = new TimeSpan(AudioPositionTicks + ticksByChar * CharacterCount); return(p); }