private List <Word> SplitWords(string linsText, string from, string to) { var words = linsText.Split(' ', StringSplitOptions.RemoveEmptyEntries); var textLength = (float)words.Sum(o => o.Length); var start = from; var duration = TimeExtend.GetDuration(from, to); List <Word> ret = new List <Word>(); foreach (var w in words) { var sec = duration * (w.Length / textLength); // 时间暂时按照单词长度做切割 var addWord = new Subtitles.Word { From = start, Text = w, }; addWord.To = TimeSpan.FromSeconds(addWord.FromSec + sec).ToString(@"hh\:mm\:ss\,fff"); start = addWord.To; ret.Add(addWord); } ret.Last().To = to; // 因为百分比切割还是会有误差,这里最后把的和字幕的放到一起 return(ret); }
List <TransBattuta> UpWrodsVersion(List <TransBattuta> battutas) { foreach (var item in battutas) { if (item.Words.Count > 0) { continue; } // 这里要对原先的文本做切割,用来和vtt的保持一致 var words = item.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries); var textLength = (float)words.Sum(o => o.Length); var start = item.From; foreach (var w in words) { var sec = item.Duration * (w.Length / textLength); // 时间暂时按照单词长度做切割 var addWord = new Subtitles.Word { From = start, Text = w, }; addWord.To = TimeSpan.FromSeconds(addWord.FromSec + sec).ToString(@"hh\:mm\:ss\,fff"); start = addWord.To; item.Words.Add(addWord); } item.Words.Last().To = item.To; // 因为百分比切割还是会有误差,这里最后把的和字幕的放到一起 } return(battutas); }