ow
This commit is contained in:
1 parent
fd48c2eb7d
commit
cb3fdca3e1
8 files changed
+339
-52
No files matched your search
@@ -13,10 +13,16 @@ namespace CloudBuilder.AI.Entity
|
||||
{
|
||||
}
|
||||
|
||||
[Column("dialogue_indc")]
|
||||
public string DialogueIndc { get; set; }
|
||||
[Column("order_index")]
|
||||
public int OrderIndex { get; set; }
|
||||
[Column("person_name")]
|
||||
public string PersonName { get; set; }
|
||||
[Column("person_mapping")]
|
||||
public string? PersonMapping { get; set; }
|
||||
[Column("updated_by")]
|
||||
public string UpdatedBy { get; set; }
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Column("person_id")]
|
||||
@@ -29,45 +35,43 @@ namespace CloudBuilder.AI.Entity
|
||||
public long ParagraphIndex { get; set; }
|
||||
[Column("sentence_index")]
|
||||
public int SentenceIndex { get; set; }
|
||||
[Column("order_index")]
|
||||
public int OrderIndex { get; set; }
|
||||
[Column("created_datetime")]
|
||||
public DateTime CreatedDatetime { get; set; }
|
||||
[Column("created_by")]
|
||||
public string CreatedBy { get; set; }
|
||||
[Column("updated_datetime")]
|
||||
public DateTime UpdatedDatetime { get; set; }
|
||||
[Column("updated_by")]
|
||||
public string UpdatedBy { get; set; }
|
||||
|
||||
public const string DIALOGUE_INDC = "DialogueIndc";
|
||||
public const string ORDER_INDEX = "OrderIndex";
|
||||
public const string PERSON_NAME = "PersonName";
|
||||
public const string PERSON_MAPPING = "PersonMapping";
|
||||
public const string UPDATED_BY = "UpdatedBy";
|
||||
public const string PERSON_ID = "PersonId";
|
||||
public const string BOOK_ID = "BookId";
|
||||
public const string CHAPTER_ID = "ChapterId";
|
||||
public const string PARAGRAPH_INDEX = "ParagraphIndex";
|
||||
public const string SENTENCE_INDEX = "SentenceIndex";
|
||||
public const string ORDER_INDEX = "OrderIndex";
|
||||
public const string CREATED_DATETIME = "CreatedDatetime";
|
||||
public const string CREATED_BY = "CreatedBy";
|
||||
public const string UPDATED_DATETIME = "UpdatedDatetime";
|
||||
public const string UPDATED_BY = "UpdatedBy";
|
||||
|
||||
public const string DB_NAME_AI_CHAPTER_PERSON = "ai_chapter_person";
|
||||
public const string DB_NAME_FIELDS="person_name,person_mapping,person_id,book_id,chapter_id,paragraph_index,sentence_index,order_index,created_datetime,created_by,updated_datetime,updated_by";
|
||||
public const string DB_NAME_FIELDS="dialogue_indc,order_index,person_name,person_mapping,updated_by,person_id,book_id,chapter_id,paragraph_index,sentence_index,created_datetime,created_by,updated_datetime";
|
||||
|
||||
public const string DB_DIALOGUE_INDC = "dialogue_indc";
|
||||
public const string DB_ORDER_INDEX = "order_index";
|
||||
public const string DB_PERSON_NAME = "person_name";
|
||||
public const string DB_PERSON_MAPPING = "person_mapping";
|
||||
public const string DB_UPDATED_BY = "updated_by";
|
||||
public const string DB_PERSON_ID = "person_id";
|
||||
public const string DB_BOOK_ID = "book_id";
|
||||
public const string DB_CHAPTER_ID = "chapter_id";
|
||||
public const string DB_PARAGRAPH_INDEX = "paragraph_index";
|
||||
public const string DB_SENTENCE_INDEX = "sentence_index";
|
||||
public const string DB_ORDER_INDEX = "order_index";
|
||||
public const string DB_CREATED_DATETIME = "created_datetime";
|
||||
public const string DB_CREATED_BY = "created_by";
|
||||
public const string DB_UPDATED_DATETIME = "updated_datetime";
|
||||
public const string DB_UPDATED_BY = "updated_by";
|
||||
|
||||
|
||||
public static AiChapterPersonEntity GetInstance()
|
||||
@@ -87,25 +91,26 @@ namespace CloudBuilder.AI.Entity
|
||||
throw new NullReferenceException("Source entity is null.");
|
||||
}
|
||||
|
||||
this.DialogueIndc = source.DialogueIndc;
|
||||
this.OrderIndex = source.OrderIndex;
|
||||
this.PersonName = source.PersonName;
|
||||
this.PersonMapping = source.PersonMapping;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
this.PersonId = source.PersonId;
|
||||
this.BookId = source.BookId;
|
||||
this.ChapterId = source.ChapterId;
|
||||
this.ParagraphIndex = source.ParagraphIndex;
|
||||
this.SentenceIndex = source.SentenceIndex;
|
||||
this.OrderIndex = source.OrderIndex;
|
||||
this.CreatedDatetime = source.CreatedDatetime;
|
||||
this.CreatedBy = source.CreatedBy;
|
||||
this.UpdatedDatetime = source.UpdatedDatetime;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
|
||||
if (includeSystemFields)
|
||||
{
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
this.CreatedDatetime = source.CreatedDatetime;
|
||||
this.CreatedBy = source.CreatedBy;
|
||||
this.UpdatedDatetime = source.UpdatedDatetime;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,45 +168,99 @@ namespace CloudBuilder.AI.Policy
|
||||
ChineseTtsVoice.Theresa
|
||||
};
|
||||
|
||||
// 1. 随机取任意一个
|
||||
public static ChineseTtsVoice GetRandom()
|
||||
|
||||
/// <summary>
|
||||
/// 百分比越大,取前面5个的机会越大
|
||||
/// </summary>
|
||||
/// <param name="percentage">0~100,推荐 50~100</param>
|
||||
/// <summary>
|
||||
/// 百分比越大,取前面5个的机会越大
|
||||
/// </summary>
|
||||
/// <param name="percentage">0~100,越大越容易选前5个</param>
|
||||
public static ChineseTtsVoice GetRandom(int percentage = 80)
|
||||
{
|
||||
var all = Enum.GetValues(typeof(ChineseTtsVoice)).Cast<ChineseTtsVoice>().ToList();
|
||||
return all[_random.Next(all.Count)];
|
||||
int totalCount = all.Count;
|
||||
|
||||
// 安全限制
|
||||
percentage = Math.Clamp(percentage, 0, 100);
|
||||
if (totalCount == 0) return default;
|
||||
|
||||
// 前5个
|
||||
int topCount = 5;
|
||||
var topItems = all.Take(topCount).ToList();
|
||||
|
||||
// 百分比越高,前5个被选中的概率越高
|
||||
double topChance = percentage / 100.0;
|
||||
|
||||
// 随机决定是否从前5个拿
|
||||
if (_random.NextDouble() < topChance && topItems.Any())
|
||||
{
|
||||
return topItems[_random.Next(topItems.Count)];
|
||||
}
|
||||
else
|
||||
{
|
||||
// 否则全量随机
|
||||
return all[_random.Next(all.Count)];
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 随机女性
|
||||
public static ChineseTtsVoice GetRandomFemale()
|
||||
// 2. 随机女性 + 百分比权重(越高越容易选前5个)
|
||||
public static ChineseTtsVoice GetRandomFemale(int weightPercentage = 80)
|
||||
{
|
||||
return _allFemales[_random.Next(_allFemales.Count)];
|
||||
return GetWeightedRandom(_allFemales, weightPercentage);
|
||||
}
|
||||
|
||||
// 3. 随机男性
|
||||
public static ChineseTtsVoice GetRandomMale()
|
||||
// 3. 随机男性 + 百分比权重
|
||||
public static ChineseTtsVoice GetRandomMale(int weightPercentage = 80)
|
||||
{
|
||||
return _allMales[_random.Next(_allMales.Count)];
|
||||
return GetWeightedRandom(_allMales, weightPercentage);
|
||||
}
|
||||
|
||||
// 4. 随机男性(传入要排除的声音,通用版 ✅)
|
||||
public static ChineseTtsVoice GetRandomMaleExclude(ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa4)
|
||||
// 4. 随机男性(排除指定)+ 百分比权重
|
||||
public static ChineseTtsVoice GetRandomMaleExclude(int weightPercentage = 80, ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa4)
|
||||
{
|
||||
var filtered = _allMales.Where(m => m != excludeVoice).ToList();
|
||||
return filtered[_random.Next(filtered.Count)];
|
||||
return GetWeightedRandom(filtered, weightPercentage);
|
||||
}
|
||||
|
||||
// 5. 随机女性(传入要排除的声音,通用版 ✅)
|
||||
public static ChineseTtsVoice GetRandomFemaleExclude(ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa0)
|
||||
// 5. 随机女性(排除指定)+ 百分比权重
|
||||
public static ChineseTtsVoice GetRandomFemaleExclude(int weightPercentage = 80, ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa0)
|
||||
{
|
||||
var filtered = _allFemales.Where(f => f != excludeVoice).ToList();
|
||||
return filtered[_random.Next(filtered.Count)];
|
||||
return GetWeightedRandom(filtered, weightPercentage);
|
||||
}
|
||||
|
||||
// 1. 随机取任意一个
|
||||
public static ChineseTtsVoice GetRandomExclude()
|
||||
// 1. 随机任意一个(排除默认)+ 百分比权重
|
||||
public static ChineseTtsVoice GetRandomExclude(int weightPercentage = 80)
|
||||
{
|
||||
var all = Enum.GetValues(typeof(ChineseTtsVoice)).Cast<ChineseTtsVoice>().ToList();
|
||||
all = all.Where(f => f != DefaultFemale && f != DefaultMale).ToList();
|
||||
return all[_random.Next(all.Count)];
|
||||
return GetWeightedRandom(all, weightPercentage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加权随机:百分比越高,前5个概率越大
|
||||
/// </summary>
|
||||
private static ChineseTtsVoice GetWeightedRandom(List<ChineseTtsVoice> list, int percentage)
|
||||
{
|
||||
if (list == null || list.Count == 0)
|
||||
return default;
|
||||
|
||||
// 确保 0~100 之间
|
||||
percentage = Math.Clamp(percentage, 0, 100);
|
||||
|
||||
const int topCount = 5; // 固定前5个
|
||||
var topItems = list.Take(topCount).ToList();
|
||||
|
||||
// 百分比越高,越容易选前5个
|
||||
if (_random.NextDouble() < percentage / 100.0 && topItems.Any())
|
||||
{
|
||||
return topItems[_random.Next(topItems.Count)];
|
||||
}
|
||||
|
||||
// 否则全列表随机
|
||||
return list[_random.Next(list.Count)];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,14 @@ namespace CloudBuilder.AI.Service
|
||||
|
||||
AiBookData ProcessBook(string key, string encoding, string pattern);
|
||||
|
||||
IActionResult GetTtsStream(string text);
|
||||
void PackPersonNameByBookId(string bookId);
|
||||
void PackPersonName(AiChapterEntity[] chapters);
|
||||
|
||||
void GenerateMp3(AiChapterEntity[] chapters);
|
||||
void GenerateMp3ByBookId(string bookId);
|
||||
|
||||
IActionResult GetMp3Stream(AiSentenceViewEntity aiChapter);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user