Example #1
0
        List <TransBattuta> ConverVttToSubtitles(List <VTT.VttLine> battutas)
        {
            var ret = new List <TransBattuta>(battutas.Count);

            foreach (var item in battutas)
            {
                var tb = new TransBattuta()
                {
                    Id   = item.Id,
                    From = item.From,
                    To   = item.To,
                    Text = item.Text
                };

                foreach (var w in item.Words)
                {
                    tb.Words.Add(new Subtitles.Word
                    {
                        From = w.From,
                        To   = w.To,
                        Text = w.Text,
                    });
                }
                ret.Add(tb);
            }

            return(ret);
        }
Example #2
0
        void TransLine(TransBattuta line)
        {
            bool notTrnas = string.IsNullOrEmpty(line.Trans2) || line.Trans == line.Trans2;

            try
            {
                if (nextRunTimes > DateTime.Now)
                {
                    return;
                }

                var trans = api.GetTrans(line.Text, "en", "zh");
                if (!string.IsNullOrEmpty(trans))
                {
                    line.Trans = trans;
                    Console.WriteLine(trans);
                    if (notTrnas)
                    {
                        line.Trans2 = line.Trans;
                    }
                }
            }
            catch (Exception ex)
            {
                nextRunTimes = DateTime.Now.AddMinutes(1); // 发生错误,就等1分钟后,才能进行翻译处理
                Logger.Error($"翻译接口有问题: {ex.Message}");
            }
        }
Example #3
0
        List <TransBattuta> ConverSrtToSubtitles(List <Battuta> battutas)
        {
            var ret = new List <TransBattuta>(battutas.Count);

            foreach (var item in battutas)
            {
                var tb = new TransBattuta()
                {
                    Id   = item.Id,
                    From = item.From,
                    To   = item.To,
                    Text = item.Text
                };

                // 这里要对原先的文本做切割,用来和vtt的保持一致
                tb.Words = SplitWords(item.Text, item.From, item.To);

                ret.Add(tb);
            }

            return(ret);
        }