This commit is contained in:
owenchen committed 2026-06-22 17:02:26 +08:00
1 parent 77a62b8d88
commit 2c6475b2d5
10 files changed
+341 -234

No files matched your search

+37 -1
View File
@@ -9,10 +9,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace CloudBuilder.Topshelf.Task.AI
{
//task:NameGenderPredictorTask book_id:B000010 from_chapter_id:177 to_chapter_id:200
//task:NameGenderPredictorTask book_id:B000011 from_chapter_id:177 to_chapter_id:200
public class NameGenderPredictorTask : IScheduleTask
{
private readonly IApplicationService service;
@@ -59,6 +60,41 @@ namespace CloudBuilder.Topshelf.Task.AI
ConsoleOutput.UpdateProgress(processedLines, totalLines);
}
string[] personNames = aiSentences.Select(x => x.PersonName).Distinct().ToArray();
if (personNames != null && personNames.Length > 0)
{
AiBookPersonEntity aiBookPersonEntity;
IRepository<AiBookPersonEntity> repositoryAiBookPersonEntity = service.GetRepository<IRepository<AiBookPersonEntity>>();
AiBookPersonEntity[] bps = repositoryAiBookPersonEntity.DetachedEntities.Where(x => x.BookId == aiSentences[0].BookId).ToArray();
if (bps != null && bps.Length > 0)
{
repositoryAiBookPersonEntity.DeleteNow(bps);
}
List<AiBookPersonEntity> ps = new List<AiBookPersonEntity>();
//旁白
aiBookPersonEntity = new AiBookPersonEntity();
aiBookPersonEntity.BookId = aiSentences[0].BookId;
aiBookPersonEntity.PersonName = null;
aiBookPersonEntity.ActorName = SoVITSTtsVoiceRandom.GetRandomByGender("女性").ToString();
ps.Add(aiBookPersonEntity);
foreach (var personName in personNames)
{
if (string.IsNullOrEmpty(personName)) continue;
aiBookPersonEntity = new AiBookPersonEntity();
aiBookPersonEntity.BookId = aiSentences[0].BookId;
aiBookPersonEntity.PersonName = personName;
aiBookPersonEntity.ActorName = SoVITSTtsVoiceRandom.GetRandomByGender(NameGenderPredictor.IsMale(personName) == true ? "男性" : "女性").ToString();
ps.Add(aiBookPersonEntity);
}
repositoryAiBookPersonEntity.InsertNow(ps);
}
repositoryAiSentenceEntity.UpdateNow(aiSentences);
}
catch (Exception ex)