优化 完善gpt请求参数,gpt版本
This commit is contained in:
parent
b48c86936b
commit
c14842a99d
|
|
@ -46,8 +46,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//时间片
|
//时间片
|
||||||
let segment = displayButton.find(s => currentTime >= s.startTime
|
let segment = displayButton.findLast(s => currentTime >= s.startTime)
|
||||||
&& currentTime <= s.endTime)
|
|
||||||
if (segment) {
|
if (segment) {
|
||||||
segment.button.style.backgroundColor = "rgb(238, 200, 118)";
|
segment.button.style.backgroundColor = "rgb(238, 200, 118)";
|
||||||
if (lastSegments && lastSegments != segment) lastSegments.button.style.backgroundColor = "rgb(240, 249, 235)";
|
if (lastSegments && lastSegments != segment) lastSegments.button.style.backgroundColor = "rgb(240, 249, 235)";
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,11 @@ namespace Learn.VideoAnalysis.Components.Pages
|
||||||
{
|
{
|
||||||
var sf = ((int)((segment.StartTime ?? 0) / 60)).ToString().PadLeft(2,'0');
|
var sf = ((int)((segment.StartTime ?? 0) / 60)).ToString().PadLeft(2,'0');
|
||||||
var sm = ((int)((segment.StartTime ?? 0) % 60)).ToString().PadLeft(2, '0');
|
var sm = ((int)((segment.StartTime ?? 0) % 60)).ToString().PadLeft(2, '0');
|
||||||
var ef = ((int)((segment.EndTime ?? 0) / 60)).ToString().PadLeft(2, '0');
|
return $"{sf}:{sm}";
|
||||||
var em = ((int)((segment.EndTime ?? 0) % 60)).ToString().PadLeft(2, '0');
|
//var ef = ((int)((segment.EndTime ?? 0) / 60)).ToString().PadLeft(2, '0');
|
||||||
return $"{sf}:{sm} - {ef}: {em}";
|
//var em = ((int)((segment.EndTime ?? 0) % 60)).ToString().PadLeft(2, '0');
|
||||||
}
|
//return $"{sf}:{sm} - {ef}: {em}";
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化
|
/// 初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,45 @@ namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
/// 对话
|
/// 对话
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Message[] messages { get; set; }
|
public Message[] messages { get; set; }
|
||||||
public string model { get; set; } = "gpt-4o";
|
/// <summary>
|
||||||
|
/// 提问种子值[用来确保 相同参数请求尽可能返回相同参数]
|
||||||
|
/// <para>默认:null</para>
|
||||||
|
/// <para>此功能处于 Beta 阶段。 如果指定,我们的系统将尽最大努力确定性地采样,这样具有相同 and 参数的重复请求应该返回相同的结果。 无法保证确定性,您应该参考 response 参数来监控后端的变化</para>
|
||||||
|
/// </summary>
|
||||||
|
public int? seed { get; set; } =null;
|
||||||
|
public string model { get; set; } = ChatGPTType.GPT4o;
|
||||||
|
/// <summary>
|
||||||
|
/// 要使用的采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使其更加集中和确定。 我们通常建议更改此项或同时更改两者。top_p
|
||||||
|
/// <para> 默认为 1</para>
|
||||||
|
/// <para> <see cref="ChatRequest.top_p"/>联动</para>
|
||||||
|
/// </summary>
|
||||||
public float temperature { get; set; } = 0.2f;
|
public float temperature { get; set; } = 0.2f;
|
||||||
public float max_tokens { get; set; } = 4000;
|
/// <summary>
|
||||||
public object response_format = new { type = "json_object" }; // 指定结构化输出格式
|
/// 一种替代温度采样的方法,称为原子核采样, 其中,模型考虑具有top_p概率的标记的结果 质量。所以 0.1 表示仅包含前 10% 概率质量的代币 被考
|
||||||
|
/// <para>建议与<see cref="ChatRequest.temperature"/>联动</para>
|
||||||
|
/// </summary>
|
||||||
|
public float top_p { get; set; } = 0.5f;
|
||||||
|
public float max_completion_tokens { get; set; } = 5000;
|
||||||
|
/// <summary>
|
||||||
|
/// 一个对象,用于指定模型必须输出的格式。设置为 enable 结构化输出,确保模型与您提供的 JSON 匹配 图式。
|
||||||
|
/// </summary>
|
||||||
|
public object response_format = new { type = "json_object" };
|
||||||
|
/// <summary>
|
||||||
|
/// 流式返回
|
||||||
|
/// </summary>
|
||||||
|
public bool stream =false;
|
||||||
|
/// <summary>
|
||||||
|
/// 您希望模型为此请求生成的 Output types。 大多数模型都能够生成文本,这是
|
||||||
|
/// <para>默认设置: ["text"]</para>
|
||||||
|
/// <para>该模型还可用于生成音频。自 请求此模型同时生成文本和音频响应,您可以 用:gpt-4o-audio-preview["text", "audio"]</para>
|
||||||
|
/// </summary>
|
||||||
|
public string modalities = "[\"json\"]";
|
||||||
|
/// <summary>
|
||||||
|
/// ai引导新话题
|
||||||
|
/// <para>默认-2 范围[-2~2]</para>
|
||||||
|
/// </summary>
|
||||||
|
public int presence_penalty = -2;
|
||||||
|
|
||||||
}
|
}
|
||||||
public class Message
|
public class Message
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
|
{
|
||||||
|
public class ChatGPTType
|
||||||
|
{
|
||||||
|
public static string GPT4oLatest = "chatgpt-4o-latest";
|
||||||
|
public static string GPT4o241120 = "gpt-4o-2024-11-20";
|
||||||
|
public static string GPT4o240513 = "gpt-4o-2024-05-13";
|
||||||
|
/// <summary>
|
||||||
|
/// GPT-4O 型 -> gpt-4o-2024-08-06
|
||||||
|
/// </summary>
|
||||||
|
public static string GPT4o= "gpt-4o";
|
||||||
|
|
||||||
|
public static string GPT4oMini= "gpt-4o-mini";
|
||||||
|
public static string GPT4oMini240718 = "gpt-4o-mini-2024-07-18";
|
||||||
|
|
||||||
|
public static string GPT4Turbo= "gpt-4-turbo-2024-04-09";
|
||||||
|
/// <summary>
|
||||||
|
/// gpt-4-turbo-preview gpt-4-0125-preview
|
||||||
|
/// </summary>
|
||||||
|
public static string GPT4TurboPreview = "gpt-4-turbo-preview";
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// o1 系列模型通过强化学习进行训练,以执行复杂的推理。o1 模型在回答之前会思考,在回应用户之前会产生一个漫长的内部思维链。在我们的推理指南中了解 o1 模型的功能。
|
||||||
|
///<para>目前有两种型号可供选择:</para>
|
||||||
|
///<para>O1:旨在解决跨领域的难题的推理模型</para>
|
||||||
|
///<para>O1-Mini:用于专业任务的快速且经济实惠的推理模型</para>
|
||||||
|
/// </summary>
|
||||||
|
public static string GPTo1 = "o1";
|
||||||
|
/// <summary>
|
||||||
|
/// o1 系列模型通过强化学习进行训练,以执行复杂的推理。o1 模型在回答之前会思考,在回应用户之前会产生一个漫长的内部思维链。在我们的推理指南中了解 o1 模型的功能。
|
||||||
|
///<para>目前有两种型号可供选择:</para>
|
||||||
|
///<para>O1:旨在解决跨领域的难题的推理模型</para>
|
||||||
|
///<para>O1-Mini:用于专业任务的快速且经济实惠的推理模型</para>
|
||||||
|
/// </summary>
|
||||||
|
public static string GPTo1Mini = "o1-mini";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||||
namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// kimi 文本模型
|
/// chatgpt 文本模型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Chat_GPT : IBserGPT
|
public class Chat_GPT : IBserGPT
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +48,7 @@ namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
// 如果类型相同,则扩展时间段
|
// 如果类型相同,则扩展时间段
|
||||||
if (current.Theme == next.Theme)
|
if (current.Theme == next.Theme)
|
||||||
{
|
{
|
||||||
current.EndTime = Math.Max(current.EndTime.Value, next.EndTime.Value);
|
//current.EndTime = Math.Max(current.EndTime.Value, next.EndTime.Value);
|
||||||
current.Content += next.Content;
|
current.Content += next.Content;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -90,24 +90,26 @@ namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
var fileNameInfoRes = await ChatAsync<FileNameInfo>(task, fileNamePostMessages,null, fileNameResFormat);
|
var fileNameInfoRes = await ChatAsync<FileNameInfo>(task, fileNamePostMessages,null, fileNameResFormat);
|
||||||
|
|
||||||
var captions = ExpandFunction.GetSpeakerCaptions(task);
|
var captions = ExpandFunction.GetSpeakerCaptions(task);
|
||||||
|
var maxVideoTime = captions?.TimeBase?.LastOrDefault()?.End??0;
|
||||||
var criteriaBuilder = new StringBuilder();
|
var criteriaBuilder = new StringBuilder();
|
||||||
|
|
||||||
var resFormat = """[{"StartTime":开始秒(number),"EndTime":结束秒(number),"Section":章节(string),"Theme":主题(string),"ThemeDetalis":主题详情(string),"Content":内容总结(string)}]""";
|
//var resFormat = """[{"StartTime":开始秒(number),"EndTime":结束秒(number),"Section":章节(string),"Theme":主题(string),"ThemeDetalis":主题详情(string),"Content":内容总结(string)}]""";
|
||||||
|
var resFormat = """[{"StartTime":开始秒(number),"Section":章节(string),"Theme":主题(string),"ThemeDetalis":主题详情(string),"Content":内容总结(string)}]""";
|
||||||
var know = await knowledgeInfoDB.GetFirstAsync(s => s.Name == fileNameInfoRes.授课章节);
|
var know = await knowledgeInfoDB.GetFirstAsync(s => s.Name == fileNameInfoRes.授课章节);
|
||||||
var knowledgeInfos = await knowledgeInfoDB.AsQueryable().ToChildListAsync(s => s.Parent_Id, know.Id);
|
var knowledgeInfos = await knowledgeInfoDB.AsQueryable().ToChildListAsync(s => s.Parent_Id, know.Id);
|
||||||
var knows = "数列的概念,数列的定义,项的表示,数列的表示方法,通项公式,递推公式,图像表示,数列的类型,等差数列,等比数列,其他特殊数列,数列的性质,单调性,有限性,数列的求和,等差数列求和公式,等比数列求和公式,数列极限,递推关系";
|
var knows = "数列的概念,数列的定义,项的表示,数列的表示方法,通项公式,递推公式,图像表示,数列的类型,等差数列,等比数列,其他特殊数列,数列的性质,单调性,有限性,数列的求和,等差数列求和公式,等比数列求和公式,数列极限,递推关系";
|
||||||
knows = string.Join(',', knowledgeInfos.Select(s => s.Name));
|
knows = string.Join(',', knowledgeInfos.Select(s => s.Name));
|
||||||
|
|
||||||
var postMessages =
|
var postMessages =
|
||||||
$"你的任务是分析视频字幕内容并提取出中国高考考试试题方法点,然后根据步骤分析出内容片段" +
|
$"你的任务是分析视频字幕内容并提取出中国高考考试试题方法点,然后根据步骤分析出知识片段" +
|
||||||
$"按以下步骤完成:" +
|
$"按以下步骤完成:" +
|
||||||
$"1.识别方法点:提取字幕内容中与{subject}考试属于{fileNameInfoRes.授课章节}章节相关的方法点。" +
|
$"1.识别方法点:提取字幕内容中与{subject}考试属于{fileNameInfoRes.授课章节}章节相关的方法点。" +
|
||||||
$"2.分析总结:基于提取出的方法点名称来匹配我提供的方法点名称" +
|
$"2.分析总结:基于提取出的方法点名称来匹配我提供的方法点名称" +
|
||||||
$"提供的方法点名称(基本概念,课堂练习,例题讲解,{knows})。" +
|
$"提供的方法点名称(基本概念,课堂练习,例题讲解,{knows})。" +
|
||||||
$"3.关联合并相似的知识点来合并为内容片段。" +
|
$"3.关联合并知识内容相似的知识点来合并为知识片段。" +
|
||||||
$"内容片段使用关联知识点中的最小(开始秒)和(最大)结束秒,主题为关联知识点的主题分析,内容总结为关联知识点的内容总结分析。" +
|
$"知识片段使用关联知识点中的最小开始时间主题为关联知识点的主题分析,内容总结为关联知识点的内容总结分析。" +
|
||||||
$"4.基于内容片段的内容总结加上主题来分析这个片段对主题的讲解内容为新的主题 例(数列的基本概念)。" +
|
$"4.基于'知识片段'的'内容总结'加上'主题'来分析这个片段对主题的讲解内容为新的主题 例如(数列的基本概念)。" +
|
||||||
$"5.分配空余未使用的时间段到内容相近的内容片段时间区间来获取更加详细的上下文,但是请避免内容片段之间时间重合。" +
|
$"5.分配空余未使用的时间段到内容相近的知识片段时间区间来获取更加详细的上下文,但是请避免知识片段之间时间重合。" +
|
||||||
$"输入:包含时间戳的视频字幕文本。" +
|
$"输入:包含时间戳的视频字幕文本。" +
|
||||||
$"以下是包含时间的视频字幕文本。" +
|
$"以下是包含时间的视频字幕文本。" +
|
||||||
$"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).字幕列表 {captions.Captions}" +
|
$"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).字幕列表 {captions.Captions}" +
|
||||||
|
|
@ -136,6 +138,15 @@ namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
if (questionRes.Count(s=>s.ThemeDetalis == questionRes.First().ThemeDetalis) >= 3)
|
if (questionRes.Count(s=>s.ThemeDetalis == questionRes.First().ThemeDetalis) >= 3)
|
||||||
throw new Exception("视频分段主题重复 =>" + questionRes.First().ThemeDetalis);
|
throw new Exception("视频分段主题重复 =>" + questionRes.First().ThemeDetalis);
|
||||||
|
|
||||||
|
for (int i = 0; i < questionRes.Length; i++)
|
||||||
|
{
|
||||||
|
var item = questionRes[i];
|
||||||
|
if (i == questionRes.Length - 1)
|
||||||
|
item.EndTime = maxVideoTime;
|
||||||
|
else
|
||||||
|
item.EndTime = (int)(questionRes[i + 1]?.StartTime??0) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
await RedisExpand.Redis
|
await RedisExpand.Redis
|
||||||
.HMSetAsync(RedisExpandKey.Task(task), "VideoKnows", questionRes);
|
.HMSetAsync(RedisExpandKey.Task(task), "VideoKnows", questionRes);
|
||||||
|
|
||||||
|
|
@ -171,7 +182,8 @@ namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
messageArr = messageArr.Where(s => s != null).ToArray();
|
messageArr = messageArr.Where(s => s != null).ToArray();
|
||||||
var chatRep = new ChatRequest
|
var chatRep = new ChatRequest
|
||||||
{
|
{
|
||||||
max_tokens = maxTokens,
|
model = ChatGPTType.GPT4o241120,
|
||||||
|
max_completion_tokens = maxTokens,
|
||||||
temperature = 0.2f,
|
temperature = 0.2f,
|
||||||
messages = messageArr
|
messages = messageArr
|
||||||
};
|
};
|
||||||
|
|
@ -268,7 +280,7 @@ namespace VideoAnalysisCore.AICore.GPT.ChatGPT
|
||||||
var maxTokens = 4000;
|
var maxTokens = 4000;
|
||||||
var chatRep = new ChatRequest
|
var chatRep = new ChatRequest
|
||||||
{
|
{
|
||||||
max_tokens = maxTokens,
|
max_completion_tokens = maxTokens,
|
||||||
temperature = 0.3f,
|
temperature = 0.3f,
|
||||||
messages = [
|
messages = [
|
||||||
new Message(postMessages,"system"),
|
new Message(postMessages,"system"),
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ namespace VideoAnalysisCore.AICore.GPT.Dto
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float? StartTime { get; set; }
|
public float? StartTime { get; set; }
|
||||||
public float? EndTime { get; set; }
|
public float? EndTime { get; set; }
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// 持续时间
|
///// 持续时间
|
||||||
/// </summary>
|
///// </summary>
|
||||||
public float? KeepTime => (EndTime ?? 0) - StartTime ?? 0;
|
public float? KeepTime => (EndTime ?? 0) - StartTime ?? 0;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主题
|
/// 主题
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,19 @@ using SherpaOnnx;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using VideoAnalysisCore.Common;
|
using VideoAnalysisCore.Common;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace VideoAnalysisCore.AICore.SherpaOnnx
|
namespace VideoAnalysisCore.AICore.SherpaOnnx
|
||||||
{
|
{
|
||||||
public class SenseVoice
|
public class SenseVoice
|
||||||
{
|
{
|
||||||
|
const string TransducerStr = "sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20";
|
||||||
static OfflineRecognizer OR =default!;
|
static OfflineRecognizer OR =default!;
|
||||||
//static VoiceActivityDetector VAD = default!;
|
//static VoiceActivityDetector VAD = default!;
|
||||||
static VadModelConfig VADModelConfig = default!;
|
static VadModelConfig VADModelConfig = default!;
|
||||||
|
|
@ -20,7 +24,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="numThreads"></param>
|
/// <param name="numThreads"></param>
|
||||||
/// <param name="useGPU">是否使用gpu 报错请看安装CUDA环境<see cref="https://k2-fsa.github.io/sherpa/onnx/pretrained_models/whisper/large-v3.html#run-with-gpu-float32"/></param>
|
/// <param name="useGPU">是否使用gpu 报错请看安装CUDA环境<see cref="https://k2-fsa.github.io/sherpa/onnx/pretrained_models/whisper/large-v3.html#run-with-gpu-float32"/></param>
|
||||||
public static void Init(int numThreads =4,bool useGPU=false)
|
public static void Init(int numThreads =4,bool useGPU=false,bool useHotwords = false)
|
||||||
{
|
{
|
||||||
Console.WriteLine("初始化 SenseVoice");
|
Console.WriteLine("初始化 SenseVoice");
|
||||||
OfflineRecognizerConfig config = new OfflineRecognizerConfig();
|
OfflineRecognizerConfig config = new OfflineRecognizerConfig();
|
||||||
|
|
@ -53,11 +57,25 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
|
||||||
////它指定搜索过程中要保留的活动路径数
|
////它指定搜索过程中要保留的活动路径数
|
||||||
//config.MaxActivePaths =4;
|
//config.MaxActivePaths =4;
|
||||||
#endregion
|
#endregion
|
||||||
|
//启用热词功能
|
||||||
|
if (false)
|
||||||
|
{
|
||||||
|
//热词目录
|
||||||
|
config.HotwordsFile = Path.Combine(AppCommon.AIModelFile, "Hotwords.txt");
|
||||||
|
config.DecodingMethod = "modified_beam_search";
|
||||||
|
//热词得分
|
||||||
|
config.HotwordsScore = 1.5f;
|
||||||
|
|
||||||
//热词目录
|
config.ModelConfig.ModelingUnit = "cjkchar+bpe";
|
||||||
config.HotwordsFile = string.Empty;
|
config.ModelConfig.BpeVocab = Path.Combine(AppCommon.AIModelFile, "sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20", "bpe.model");
|
||||||
//热词得分
|
config.ModelConfig.Transducer = new OfflineTransducerModelConfig()
|
||||||
config.HotwordsScore =1.5f ;
|
{
|
||||||
|
Decoder = Path.Combine(AppCommon.AIModelFile, "sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20", "decoder-epoch-99-avg-1.onnx"),
|
||||||
|
Encoder = Path.Combine(AppCommon.AIModelFile, "sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20", "encoder-epoch-99-avg-1.onnx"),
|
||||||
|
Joiner = Path.Combine(AppCommon.AIModelFile, "sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20", "joiner-epoch-99-avg-1.onnx"),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
//反转文本规范化规则 fst 的路径
|
//反转文本规范化规则 fst 的路径
|
||||||
config.RuleFsts = string.Empty;
|
config.RuleFsts = string.Empty;
|
||||||
|
|
||||||
|
|
@ -110,14 +128,14 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
|
||||||
SpeechSegment segment = VAD.Front();
|
SpeechSegment segment = VAD.Front();
|
||||||
float startTime = segment.Start / (float)sampleRate;
|
float startTime = segment.Start / (float)sampleRate;
|
||||||
float duration = segment.Samples.Length / (float)sampleRate;
|
float duration = segment.Samples.Length / (float)sampleRate;
|
||||||
OfflineStream stream = OR.CreateStream();
|
using OfflineStream stream = OR.CreateStream();
|
||||||
stream.AcceptWaveform(sampleRate, segment.Samples);
|
stream.AcceptWaveform(sampleRate, segment.Samples);
|
||||||
OR.Decode(stream);
|
OR.Decode(stream);
|
||||||
if (!string.IsNullOrEmpty(stream.Result.Text))
|
if (!string.IsNullOrEmpty(stream.Result.Text))
|
||||||
{
|
{
|
||||||
res.Add(new()
|
res.Add(new()
|
||||||
{
|
{
|
||||||
Text = stream.Result.Text,
|
Text = ExpandFunction.HandleFormula(stream.Result.Text),
|
||||||
Start = (float)Math.Round(startTime, 2, MidpointRounding.AwayFromZero),
|
Start = (float)Math.Round(startTime, 2, MidpointRounding.AwayFromZero),
|
||||||
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
|
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
|
||||||
});
|
});
|
||||||
|
|
@ -196,8 +214,8 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
|
||||||
{
|
{
|
||||||
res.Add(new()
|
res.Add(new()
|
||||||
{
|
{
|
||||||
Text = stream.Result.Text,
|
Text = ExpandFunction.HandleFormula(stream.Result.Text),
|
||||||
Start= (float)Math.Round(startTime, 2, MidpointRounding.AwayFromZero),
|
Start = (float)Math.Round(startTime, 2, MidpointRounding.AwayFromZero),
|
||||||
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
|
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
|
||||||
});
|
});
|
||||||
var progress = (float)(startTime + duration) / (totalSecond) * 100;
|
var progress = (float)(startTime + duration) / (totalSecond) * 100;
|
||||||
|
|
@ -223,7 +241,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
|
||||||
{
|
{
|
||||||
res.Add(new()
|
res.Add(new()
|
||||||
{
|
{
|
||||||
Text = stream.Result.Text,
|
Text = ExpandFunction.HandleFormula(stream.Result.Text),
|
||||||
Start = (float)Math.Round(startTime, 2, MidpointRounding.AwayFromZero),
|
Start = (float)Math.Round(startTime, 2, MidpointRounding.AwayFromZero),
|
||||||
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
|
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ using FreeRedis;
|
||||||
using Microsoft.Extensions.DependencyModel;
|
using Microsoft.Extensions.DependencyModel;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using SqlSugar.IOC;
|
using SqlSugar.IOC;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UserCenter.Model.Interface;
|
using UserCenter.Model.Interface;
|
||||||
using VideoAnalysisCore.AICore.SherpaOnnx;
|
using VideoAnalysisCore.AICore.SherpaOnnx;
|
||||||
|
|
@ -16,6 +18,7 @@ using VideoAnalysisCore.Enum;
|
||||||
using VideoAnalysisCore.Interface;
|
using VideoAnalysisCore.Interface;
|
||||||
using VideoAnalysisCore.Model.Dto;
|
using VideoAnalysisCore.Model.Dto;
|
||||||
using Whisper.net;
|
using Whisper.net;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace VideoAnalysisCore.Common
|
namespace VideoAnalysisCore.Common
|
||||||
{
|
{
|
||||||
|
|
@ -87,6 +90,32 @@ namespace VideoAnalysisCore.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ExpandFunction
|
public static class ExpandFunction
|
||||||
{
|
{
|
||||||
|
static Dictionary<string, string> FormulaData = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "阿尔法","α"},
|
||||||
|
{ "贝塔","β"},
|
||||||
|
{ "伽马","γ"},
|
||||||
|
{ "德尔塔","Δ"},
|
||||||
|
{ "派","π"},
|
||||||
|
{ "西格马","∑"},
|
||||||
|
{ "欧米伽","Ω"},
|
||||||
|
{ "普西","Ψ"},
|
||||||
|
};
|
||||||
|
static string FormulaDataKey = string.Join("|", FormulaData.Keys);
|
||||||
|
/// <summary>
|
||||||
|
/// 处理数学公式
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="f"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string HandleFormula(string f)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(f))
|
||||||
|
return f;
|
||||||
|
return Regex.Replace(f, FormulaDataKey,
|
||||||
|
match =>
|
||||||
|
FormulaData[match.Value]
|
||||||
|
);
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换 ant 查询枚举 到 sqlsuger枚举
|
/// 转换 ant 查询枚举 到 sqlsuger枚举
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,13 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="AICore\_Static\ffmpeg.exe" />
|
<None Remove="AICore\_Static\ffmpeg.exe" />
|
||||||
|
<None Remove="AICore\_Static\Hotwords.txt" />
|
||||||
<None Remove="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.int8.onnx" />
|
<None Remove="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.int8.onnx" />
|
||||||
<None Remove="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.onnx" />
|
<None Remove="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.onnx" />
|
||||||
|
<None Remove="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\bpe.model" />
|
||||||
|
<None Remove="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\decoder-epoch-99-avg-1.onnx" />
|
||||||
|
<None Remove="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\encoder-epoch-99-avg-1.onnx" />
|
||||||
|
<None Remove="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\joiner-epoch-99-avg-1.onnx" />
|
||||||
<None Remove="AICore\_Static\wespeaker\wespeaker_zh_cnceleb_resnet34_LM.onnx" />
|
<None Remove="AICore\_Static\wespeaker\wespeaker_zh_cnceleb_resnet34_LM.onnx" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
@ -17,12 +22,27 @@
|
||||||
<Content Include="AICore\_Static\ffmpeg.exe">
|
<Content Include="AICore\_Static\ffmpeg.exe">
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="AICore\_Static\Hotwords.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
<Content Include="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.int8.onnx">
|
<Content Include="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.int8.onnx">
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.onnx">
|
<Content Include="AICore\_Static\sherpa-onnx-pyannote-segmentation-3-0\model.onnx">
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\bpe.model">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\decoder-epoch-99-avg-1.onnx">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\encoder-epoch-99-avg-1.onnx">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\joiner-epoch-99-avg-1.onnx">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
<Content Include="AICore\_Static\wespeaker\wespeaker_zh_cnceleb_resnet34_LM.onnx">
|
<Content Include="AICore\_Static\wespeaker\wespeaker_zh_cnceleb_resnet34_LM.onnx">
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
@ -45,4 +65,10 @@
|
||||||
<PackageReference Include="xFFmpeg.NET" Version="6.0.0" />
|
<PackageReference Include="xFFmpeg.NET" Version="6.0.0" />
|
||||||
<PackageReference Include="AntDesign.ProLayout" Version="1.0.1" />
|
<PackageReference Include="AntDesign.ProLayout" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="AICore\_Static\sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20\decoder-epoch-99-avg-1.int8.onnx">
|
||||||
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue