From c9ef1d230c7084ee9d227a0b3edc50e7e99facd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Mon, 4 Nov 2024 18:31:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=8E=A5=E5=85=A5=20Sense?= =?UTF-8?q?Voice=E6=A8=A1=E5=9E=8B=20=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VideoAnalysisCore/Common/AppCommon.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/VideoAnalysisCore/Common/AppCommon.cs b/VideoAnalysisCore/Common/AppCommon.cs index bd7f747..bfb0b47 100644 --- a/VideoAnalysisCore/Common/AppCommon.cs +++ b/VideoAnalysisCore/Common/AppCommon.cs @@ -9,6 +9,7 @@ using System.Runtime.Loader; using System.Text; using System.Threading.Tasks; using VideoAnalysisCore.AICore.SherpaOnnx; +using VideoAnalysisCore.AICore.Whisper; using VideoAnalysisCore.Enum; using VideoAnalysisCore.Model.Dto; using Whisper.net; @@ -138,7 +139,7 @@ namespace VideoAnalysisCore.Common /// public static TotalCaptionsDto GetSpeakerCaptions(string task) { - var captionsArr = RedisExpand.Redis.HMGet(RedisExpandKey.Task(task), "Captions").FirstOrDefault(); + var captionsArr = RedisExpand.Redis.HMGet(RedisExpandKey.Task(task), "Captions").FirstOrDefault(); var speakerArr = RedisExpand.Redis.HMGet(RedisExpandKey.Task(task), "Speaker").FirstOrDefault(); if (captionsArr is null || captionsArr.Length == 0 || speakerArr is null || speakerArr.Length == 0) @@ -146,18 +147,18 @@ namespace VideoAnalysisCore.Common // 教师说话人Id var techerId = speakerArr.GroupBy(s=>s.SpeakerIndex).Select(s => (s.Key,s.Sum(x=>x.Total))) .OrderByDescending(s=>s.Item2).First().Key; - var teacherSpeaking = 0m; - var studentSpeaking = 0m; - var results = new Dictionary>(); + var teacherSpeaking = 0f; + var studentSpeaking = 0f; + var results = new Dictionary>(); foreach (var segment in captionsArr) { var spList = new List(); foreach (var speakerRes in speakerArr) { - if ((double)speakerRes.Start > segment.End.TotalSeconds) + if (speakerRes.Start > segment.End) break; - if (segment.Start.TotalSeconds <= (double)speakerRes.End - && segment.End.TotalSeconds >= (double)speakerRes.Start) + if (segment.Start <= speakerRes.End + && segment.End >= speakerRes.Start) { if (speakerRes.SpeakerIndex == techerId) teacherSpeaking += speakerRes.Total; @@ -176,22 +177,22 @@ namespace VideoAnalysisCore.Common { stringBuilder.Append(item.Value.First()); stringBuilder.Append(":"); - stringBuilder.Append(item.Key.Start.TotalSeconds); + stringBuilder.Append(item.Key.Start); stringBuilder.Append(":"); - stringBuilder.Append(item.Key.End.TotalSeconds); + stringBuilder.Append(item.Key.End); stringBuilder.Append(":"); stringBuilder.Append(item.Key.Text); stringBuilder.Append("|"); } return new TotalCaptionsDto { - StudentSpeaking = studentSpeaking, - TeacherSpeaking = teacherSpeaking, + StudentSpeaking = (decimal)studentSpeaking, + TeacherSpeaking = (decimal)teacherSpeaking, Captions = stringBuilder.ToString(), TimeBase = results.Select(s=>new TimeBase() { - Start = s.Key.Start.TotalSeconds, - End = s.Key.End.TotalSeconds, + Start = s.Key.Start, + End = s.Key.End, Content = s.Key.Text, TimeBaseType = s.Value.Count == 1 && s.Value.First() == techerId ? TimeBaseTypeEnum.教师讲授