ow
This commit is contained in:
parent
fd48c2eb7d
commit
cb3fdca3e1
17
CloudBuilder.AI.Gui/AiBookOperationPage.Designer.cs
generated
17
CloudBuilder.AI.Gui/AiBookOperationPage.Designer.cs
generated
@ -82,6 +82,7 @@ namespace CloudBuilder.AI.Gui
|
|||||||
processBut = new Krypton.Toolkit.KryptonButton();
|
processBut = new Krypton.Toolkit.KryptonButton();
|
||||||
extractNamesBut = new Krypton.Toolkit.KryptonButton();
|
extractNamesBut = new Krypton.Toolkit.KryptonButton();
|
||||||
uploadBut = new Krypton.Toolkit.KryptonButton();
|
uploadBut = new Krypton.Toolkit.KryptonButton();
|
||||||
|
generaterMp3But = new Krypton.Toolkit.KryptonButton();
|
||||||
kryptonPanel2 = new Krypton.Toolkit.KryptonPanel();
|
kryptonPanel2 = new Krypton.Toolkit.KryptonPanel();
|
||||||
mainPanel = new TableLayoutPanel();
|
mainPanel = new TableLayoutPanel();
|
||||||
topPanel = new TableLayoutPanel();
|
topPanel = new TableLayoutPanel();
|
||||||
@ -614,16 +615,17 @@ namespace CloudBuilder.AI.Gui
|
|||||||
processPanel.ColumnStyles.Add(new ColumnStyle());
|
processPanel.ColumnStyles.Add(new ColumnStyle());
|
||||||
processPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
processPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
processPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
processPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
processPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 80F));
|
processPanel.ColumnStyles.Add(new ColumnStyle());
|
||||||
processPanel.Controls.Add(processBut, 1, 0);
|
processPanel.Controls.Add(processBut, 1, 0);
|
||||||
processPanel.Controls.Add(extractNamesBut, 2, 0);
|
processPanel.Controls.Add(extractNamesBut, 2, 0);
|
||||||
processPanel.Controls.Add(uploadBut, 0, 0);
|
processPanel.Controls.Add(uploadBut, 0, 0);
|
||||||
|
processPanel.Controls.Add(generaterMp3But, 3, 0);
|
||||||
processPanel.Location = new Point(377, 127);
|
processPanel.Location = new Point(377, 127);
|
||||||
processPanel.Margin = new Padding(0);
|
processPanel.Margin = new Padding(0);
|
||||||
processPanel.Name = "processPanel";
|
processPanel.Name = "processPanel";
|
||||||
processPanel.RowCount = 1;
|
processPanel.RowCount = 1;
|
||||||
processPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
processPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
||||||
processPanel.Size = new Size(356, 31);
|
processPanel.Size = new Size(373, 31);
|
||||||
processPanel.TabIndex = 6;
|
processPanel.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// processBut
|
// processBut
|
||||||
@ -656,6 +658,16 @@ namespace CloudBuilder.AI.Gui
|
|||||||
uploadBut.Values.Text = "上传";
|
uploadBut.Values.Text = "上传";
|
||||||
uploadBut.Click += uploadBut_Click;
|
uploadBut.Click += uploadBut_Click;
|
||||||
//
|
//
|
||||||
|
// generaterMp3But
|
||||||
|
//
|
||||||
|
generaterMp3But.Location = new Point(279, 3);
|
||||||
|
generaterMp3But.Name = "generaterMp3But";
|
||||||
|
generaterMp3But.Size = new Size(91, 25);
|
||||||
|
generaterMp3But.TabIndex = 2;
|
||||||
|
generaterMp3But.Values.Image = Properties.Resources.MoveNext;
|
||||||
|
generaterMp3But.Values.Text = "生成MP3";
|
||||||
|
generaterMp3But.Click += generaterMp3But_Click;
|
||||||
|
//
|
||||||
// kryptonPanel2
|
// kryptonPanel2
|
||||||
//
|
//
|
||||||
kryptonPanel2.Dock = DockStyle.Fill;
|
kryptonPanel2.Dock = DockStyle.Fill;
|
||||||
@ -979,5 +991,6 @@ namespace CloudBuilder.AI.Gui
|
|||||||
private Krypton.Toolkit.KryptonDataGridViewTextBoxColumn genderCol;
|
private Krypton.Toolkit.KryptonDataGridViewTextBoxColumn genderCol;
|
||||||
private Krypton.Toolkit.KryptonDataGridViewTextBoxColumn sentimentCol;
|
private Krypton.Toolkit.KryptonDataGridViewTextBoxColumn sentimentCol;
|
||||||
private Krypton.Toolkit.KryptonDataGridViewComboBoxColumn sentenceStatusCol;
|
private Krypton.Toolkit.KryptonDataGridViewComboBoxColumn sentenceStatusCol;
|
||||||
|
private Krypton.Toolkit.KryptonButton generaterMp3But;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -780,13 +780,12 @@ namespace CloudBuilder.AI.Gui
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AiChapterEntity chapter = dataGv.GetRowData<AiChapterEntity>(dataGv.SelectedCells[0].RowIndex);
|
AiChapterEntity[] chapters = dataGv.GetSelectedRowsData<AiChapterEntity>();
|
||||||
|
|
||||||
//aiBookRequest.ExtractNamesByChapterGuid(data.AiBook.BookId, chapter.ChapterId);
|
if (chapters != null)
|
||||||
|
aiBookRequest.PackPersonName(chapters);
|
||||||
AiSentenceViewEntity[] aiSentences = aiSentenceRequest.FindByChapterId(chapter.ChapterId);
|
else
|
||||||
|
aiBookRequest.PackPersonNameByBookId(data.AiBook.BookId);
|
||||||
sentenceGv.SetDataSource(aiSentences);
|
|
||||||
|
|
||||||
ShowMessageBox.ShowInfo(securityMessagePolicy.ComposeMessage(SecurityMessagePolicy.GUI_SUCCEED_UPDATED_NULL));
|
ShowMessageBox.ShowInfo(securityMessagePolicy.ComposeMessage(SecurityMessagePolicy.GUI_SUCCEED_UPDATED_NULL));
|
||||||
|
|
||||||
@ -819,7 +818,7 @@ namespace CloudBuilder.AI.Gui
|
|||||||
|
|
||||||
AiSentenceViewEntity sentence = sentenceGv.GetRowData<AiSentenceViewEntity>(sentenceGv.SelectedCells[0].RowIndex);
|
AiSentenceViewEntity sentence = sentenceGv.GetRowData<AiSentenceViewEntity>(sentenceGv.SelectedCells[0].RowIndex);
|
||||||
|
|
||||||
using (Stream audioStream = ServiceHelper.GetService<IServiceRequest>()!.PostStreamAsync("/AiBook/GetTtsStream?text=" + sentence.Content, null, string.Empty).GetAwaiter().GetResult())
|
using (Stream audioStream = ServiceHelper.GetService<IServiceRequest>()!.PostStreamAsync("/AiBook/GetMp3Stream", null, sentence).GetAwaiter().GetResult())
|
||||||
{
|
{
|
||||||
PlayMp3Stream(audioStream);
|
PlayMp3Stream(audioStream);
|
||||||
}
|
}
|
||||||
@ -915,5 +914,41 @@ namespace CloudBuilder.AI.Gui
|
|||||||
UseShellExecute = true // 使用Windows Shell执行
|
UseShellExecute = true // 使用Windows Shell执行
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void generaterMp3But_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dataGv.RowCount <= 0 || dataGv.SelectedCells.Count <= 0)
|
||||||
|
{
|
||||||
|
ShowMessageBox.ShowInfo(securityMessagePolicy.ComposeMessage(SecurityMessagePolicy.GUI_WS_RECORD_NOT_FOUND));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AiChapterEntity[] chapters = dataGv.GetSelectedRowsData<AiChapterEntity>();
|
||||||
|
|
||||||
|
if (chapters != null)
|
||||||
|
aiBookRequest.GenerateMp3(chapters);
|
||||||
|
else
|
||||||
|
aiBookRequest.GenerateMp3ByBookId(data.AiBook.BookId);
|
||||||
|
|
||||||
|
ShowMessageBox.ShowInfo(securityMessagePolicy.ComposeMessage(SecurityMessagePolicy.GUI_SUCCEED_UPDATED_NULL));
|
||||||
|
|
||||||
|
guidSearchTxt.Text = data.AiBook.BookId;
|
||||||
|
Search();
|
||||||
|
}
|
||||||
|
catch (ValidatedException ex)
|
||||||
|
{
|
||||||
|
ShowMessageBox.ShowInfo(ex.Message);
|
||||||
|
}
|
||||||
|
catch (ServiceErrorException ex)
|
||||||
|
{
|
||||||
|
ShowMessageBox.ShowError(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ShowMessageBox.ShowError(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System.Diagnostics.Contracts;
|
using System.Diagnostics.Contracts;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
namespace CloudBuilder.AI.Service
|
namespace CloudBuilder.AI.Service
|
||||||
@ -250,13 +251,24 @@ namespace CloudBuilder.AI.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Find)]
|
//public IActionResult GetTtsStream(string text)
|
||||||
public IActionResult GetTtsStream(string text)
|
//{
|
||||||
{
|
// string fileDownloadName = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice", DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3");
|
||||||
string fileDownloadName = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice", DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3");
|
|
||||||
|
|
||||||
string param = PackParameters(ChineseTtsVoice.Sherpa2.ToString(), fileDownloadName, text);
|
// string param = PackParameters(ChineseTtsVoice.Sherpa2.ToString(), fileDownloadName, text);
|
||||||
RunMyProcess(service.Configuration["CloudBuilder.Topshelf:Path"], param);
|
// RunMyProcess(service.Configuration["CloudBuilder.Topshelf:Path"], param);
|
||||||
|
|
||||||
|
// var stream = System.IO.File.OpenRead(fileDownloadName);
|
||||||
|
|
||||||
|
// string contentType = "application/octet-stream";
|
||||||
|
|
||||||
|
// return new FileStreamResult(stream, contentType) { FileDownloadName = fileDownloadName };
|
||||||
|
//}
|
||||||
|
|
||||||
|
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Find)]
|
||||||
|
public IActionResult GetMp3Stream(AiSentenceViewEntity aiSentence)
|
||||||
|
{
|
||||||
|
string fileDownloadName = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice", string.Format("{0}_{1}.mp3", aiSentence.BookId, aiSentence.ChapterId));
|
||||||
|
|
||||||
var stream = System.IO.File.OpenRead(fileDownloadName);
|
var stream = System.IO.File.OpenRead(fileDownloadName);
|
||||||
|
|
||||||
@ -264,13 +276,81 @@ namespace CloudBuilder.AI.Service
|
|||||||
|
|
||||||
return new FileStreamResult(stream, contentType) { FileDownloadName = fileDownloadName };
|
return new FileStreamResult(stream, contentType) { FileDownloadName = fileDownloadName };
|
||||||
}
|
}
|
||||||
private string PackParameters(string voice, string save_path, string text)
|
|
||||||
|
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Find)]
|
||||||
|
public void GenerateMp3(AiChapterEntity[] chapters)
|
||||||
{
|
{
|
||||||
|
string save_path = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice");
|
||||||
|
foreach (AiChapterEntity sentence in chapters)
|
||||||
|
{
|
||||||
|
string param = PackTtsParameters(ChineseTtsVoice.Sherpa2.ToString(), save_path, sentence.BookId, sentence.ChapterId.ToString());
|
||||||
|
RunMyProcess(service.Configuration["CloudBuilder.Topshelf:Path"], param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Find)]
|
||||||
|
public void GenerateMp3ByBookId(string bookId)
|
||||||
|
{
|
||||||
|
IRepository<AiChapterEntity> repositoryAiChapterEntity = repository.GetRepository<IRepository<AiChapterEntity>>();
|
||||||
|
AiChapterEntity[] chapters
|
||||||
|
= repositoryAiChapterEntity.DetachedEntities.Where(x => x.BookId == bookId).OrderBy(x => x.ChapterId).ToArray();
|
||||||
|
|
||||||
|
string save_path = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice");
|
||||||
|
foreach (AiChapterEntity sentence in chapters)
|
||||||
|
{
|
||||||
|
string param = PackTtsParameters(ChineseTtsVoice.Sherpa2.ToString(), save_path, sentence.BookId, sentence.ChapterId.ToString());
|
||||||
|
RunMyProcess(service.Configuration["CloudBuilder.Topshelf:Path"], param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Find)]
|
||||||
|
public void PackPersonNameByBookId(string bookId)
|
||||||
|
{
|
||||||
|
IRepository<AiChapterEntity> repositoryAiChapterEntity = repository.GetRepository<IRepository<AiChapterEntity>>();
|
||||||
|
AiChapterEntity[] chapters
|
||||||
|
= repositoryAiChapterEntity.DetachedEntities.Where(x => x.BookId == bookId).OrderBy(x => x.ChapterId).ToArray();
|
||||||
|
|
||||||
|
string save_path = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice");
|
||||||
|
foreach (AiChapterEntity aiChapter in chapters)
|
||||||
|
{
|
||||||
|
string param = PackPersonNameParameters(ChineseTtsVoice.Sherpa2.ToString(), save_path, aiChapter.BookId, aiChapter.ChapterId.ToString());
|
||||||
|
RunMyProcess(service.Configuration["CloudBuilder.Topshelf:Path"], param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Find)]
|
||||||
|
public void PackPersonName(AiChapterEntity[] chapters)
|
||||||
|
{
|
||||||
|
string save_path = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice");
|
||||||
|
foreach (AiChapterEntity aiChapter in chapters)
|
||||||
|
{
|
||||||
|
string param = PackPersonNameParameters(ChineseTtsVoice.Sherpa2.ToString(), save_path, aiChapter.BookId, aiChapter.ChapterId.ToString());
|
||||||
|
RunMyProcess(service.Configuration["CloudBuilder.Topshelf:Path"], param);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private string PackPersonNameParameters(string voice, string save_path, string bookId, string chapterId)
|
||||||
|
{
|
||||||
|
//task:ChineseNameExtractorTask book_id:B000008 chapter_id:3
|
||||||
|
List<string> para = new List<string>();
|
||||||
|
para.Add("task:" + "ChineseNameExtractorTask");
|
||||||
|
para.Add("book_id:" + bookId);
|
||||||
|
para.Add("chapter_id:" + chapterId);
|
||||||
|
return para.ToArray().ToDelimiteredList(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
private string PackTtsParameters(string voice, string save_path, string bookId, string chapterId)
|
||||||
|
{
|
||||||
|
//task:TtsTask book_id:B000008 chapter_id:3 speed:1 voice:Sherpa2 actor:韩立 actor_voice:Sherpa1 save_path:D:\\Net8\\FileServer\\Backup\\DmsFile\\voice
|
||||||
List<string> para = new List<string>();
|
List<string> para = new List<string>();
|
||||||
para.Add("task:" + "TtsTask");
|
para.Add("task:" + "TtsTask");
|
||||||
|
para.Add("book_id:" + bookId);
|
||||||
|
para.Add("chapter_id:" + chapterId);
|
||||||
para.Add("voice:" + voice);
|
para.Add("voice:" + voice);
|
||||||
para.Add("save_path:" + save_path);
|
para.Add("save_path:" + save_path);
|
||||||
para.Add("text:" + text.Replace(":", ":"));
|
para.Add("speed:1");
|
||||||
|
para.Add("actor:NA");
|
||||||
return para.ToArray().ToDelimiteredList(' ');
|
return para.ToArray().ToDelimiteredList(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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")]
|
[Column("person_name")]
|
||||||
public string PersonName { get; set; }
|
public string PersonName { get; set; }
|
||||||
[Column("person_mapping")]
|
[Column("person_mapping")]
|
||||||
public string? PersonMapping { get; set; }
|
public string? PersonMapping { get; set; }
|
||||||
|
[Column("updated_by")]
|
||||||
|
public string UpdatedBy { get; set; }
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
[Column("person_id")]
|
[Column("person_id")]
|
||||||
@ -29,45 +35,43 @@ namespace CloudBuilder.AI.Entity
|
|||||||
public long ParagraphIndex { get; set; }
|
public long ParagraphIndex { get; set; }
|
||||||
[Column("sentence_index")]
|
[Column("sentence_index")]
|
||||||
public int SentenceIndex { get; set; }
|
public int SentenceIndex { get; set; }
|
||||||
[Column("order_index")]
|
|
||||||
public int OrderIndex { get; set; }
|
|
||||||
[Column("created_datetime")]
|
[Column("created_datetime")]
|
||||||
public DateTime CreatedDatetime { get; set; }
|
public DateTime CreatedDatetime { get; set; }
|
||||||
[Column("created_by")]
|
[Column("created_by")]
|
||||||
public string CreatedBy { get; set; }
|
public string CreatedBy { get; set; }
|
||||||
[Column("updated_datetime")]
|
[Column("updated_datetime")]
|
||||||
public DateTime UpdatedDatetime { get; set; }
|
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_NAME = "PersonName";
|
||||||
public const string PERSON_MAPPING = "PersonMapping";
|
public const string PERSON_MAPPING = "PersonMapping";
|
||||||
|
public const string UPDATED_BY = "UpdatedBy";
|
||||||
public const string PERSON_ID = "PersonId";
|
public const string PERSON_ID = "PersonId";
|
||||||
public const string BOOK_ID = "BookId";
|
public const string BOOK_ID = "BookId";
|
||||||
public const string CHAPTER_ID = "ChapterId";
|
public const string CHAPTER_ID = "ChapterId";
|
||||||
public const string PARAGRAPH_INDEX = "ParagraphIndex";
|
public const string PARAGRAPH_INDEX = "ParagraphIndex";
|
||||||
public const string SENTENCE_INDEX = "SentenceIndex";
|
public const string SENTENCE_INDEX = "SentenceIndex";
|
||||||
public const string ORDER_INDEX = "OrderIndex";
|
|
||||||
public const string CREATED_DATETIME = "CreatedDatetime";
|
public const string CREATED_DATETIME = "CreatedDatetime";
|
||||||
public const string CREATED_BY = "CreatedBy";
|
public const string CREATED_BY = "CreatedBy";
|
||||||
public const string UPDATED_DATETIME = "UpdatedDatetime";
|
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_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_NAME = "person_name";
|
||||||
public const string DB_PERSON_MAPPING = "person_mapping";
|
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_PERSON_ID = "person_id";
|
||||||
public const string DB_BOOK_ID = "book_id";
|
public const string DB_BOOK_ID = "book_id";
|
||||||
public const string DB_CHAPTER_ID = "chapter_id";
|
public const string DB_CHAPTER_ID = "chapter_id";
|
||||||
public const string DB_PARAGRAPH_INDEX = "paragraph_index";
|
public const string DB_PARAGRAPH_INDEX = "paragraph_index";
|
||||||
public const string DB_SENTENCE_INDEX = "sentence_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_DATETIME = "created_datetime";
|
||||||
public const string DB_CREATED_BY = "created_by";
|
public const string DB_CREATED_BY = "created_by";
|
||||||
public const string DB_UPDATED_DATETIME = "updated_datetime";
|
public const string DB_UPDATED_DATETIME = "updated_datetime";
|
||||||
public const string DB_UPDATED_BY = "updated_by";
|
|
||||||
|
|
||||||
|
|
||||||
public static AiChapterPersonEntity GetInstance()
|
public static AiChapterPersonEntity GetInstance()
|
||||||
@ -87,25 +91,26 @@ namespace CloudBuilder.AI.Entity
|
|||||||
throw new NullReferenceException("Source entity is null.");
|
throw new NullReferenceException("Source entity is null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.DialogueIndc = source.DialogueIndc;
|
||||||
|
this.OrderIndex = source.OrderIndex;
|
||||||
this.PersonName = source.PersonName;
|
this.PersonName = source.PersonName;
|
||||||
this.PersonMapping = source.PersonMapping;
|
this.PersonMapping = source.PersonMapping;
|
||||||
|
this.UpdatedBy = source.UpdatedBy;
|
||||||
this.PersonId = source.PersonId;
|
this.PersonId = source.PersonId;
|
||||||
this.BookId = source.BookId;
|
this.BookId = source.BookId;
|
||||||
this.ChapterId = source.ChapterId;
|
this.ChapterId = source.ChapterId;
|
||||||
this.ParagraphIndex = source.ParagraphIndex;
|
this.ParagraphIndex = source.ParagraphIndex;
|
||||||
this.SentenceIndex = source.SentenceIndex;
|
this.SentenceIndex = source.SentenceIndex;
|
||||||
this.OrderIndex = source.OrderIndex;
|
|
||||||
this.CreatedDatetime = source.CreatedDatetime;
|
this.CreatedDatetime = source.CreatedDatetime;
|
||||||
this.CreatedBy = source.CreatedBy;
|
this.CreatedBy = source.CreatedBy;
|
||||||
this.UpdatedDatetime = source.UpdatedDatetime;
|
this.UpdatedDatetime = source.UpdatedDatetime;
|
||||||
this.UpdatedBy = source.UpdatedBy;
|
|
||||||
|
|
||||||
if (includeSystemFields)
|
if (includeSystemFields)
|
||||||
{
|
{
|
||||||
|
this.UpdatedBy = source.UpdatedBy;
|
||||||
this.CreatedDatetime = source.CreatedDatetime;
|
this.CreatedDatetime = source.CreatedDatetime;
|
||||||
this.CreatedBy = source.CreatedBy;
|
this.CreatedBy = source.CreatedBy;
|
||||||
this.UpdatedDatetime = source.UpdatedDatetime;
|
this.UpdatedDatetime = source.UpdatedDatetime;
|
||||||
this.UpdatedBy = source.UpdatedBy;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -168,45 +168,99 @@ namespace CloudBuilder.AI.Policy
|
|||||||
ChineseTtsVoice.Theresa
|
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();
|
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. 随机女性
|
// 2. 随机女性 + 百分比权重(越高越容易选前5个)
|
||||||
public static ChineseTtsVoice GetRandomFemale()
|
public static ChineseTtsVoice GetRandomFemale(int weightPercentage = 80)
|
||||||
{
|
{
|
||||||
return _allFemales[_random.Next(_allFemales.Count)];
|
return GetWeightedRandom(_allFemales, weightPercentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 随机男性
|
// 3. 随机男性 + 百分比权重
|
||||||
public static ChineseTtsVoice GetRandomMale()
|
public static ChineseTtsVoice GetRandomMale(int weightPercentage = 80)
|
||||||
{
|
{
|
||||||
return _allMales[_random.Next(_allMales.Count)];
|
return GetWeightedRandom(_allMales, weightPercentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 随机男性(传入要排除的声音,通用版 ✅)
|
// 4. 随机男性(排除指定)+ 百分比权重
|
||||||
public static ChineseTtsVoice GetRandomMaleExclude(ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa4)
|
public static ChineseTtsVoice GetRandomMaleExclude(int weightPercentage = 80, ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa4)
|
||||||
{
|
{
|
||||||
var filtered = _allMales.Where(m => m != excludeVoice).ToList();
|
var filtered = _allMales.Where(m => m != excludeVoice).ToList();
|
||||||
return filtered[_random.Next(filtered.Count)];
|
return GetWeightedRandom(filtered, weightPercentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 随机女性(传入要排除的声音,通用版 ✅)
|
// 5. 随机女性(排除指定)+ 百分比权重
|
||||||
public static ChineseTtsVoice GetRandomFemaleExclude(ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa0)
|
public static ChineseTtsVoice GetRandomFemaleExclude(int weightPercentage = 80, ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa0)
|
||||||
{
|
{
|
||||||
var filtered = _allFemales.Where(f => f != excludeVoice).ToList();
|
var filtered = _allFemales.Where(f => f != excludeVoice).ToList();
|
||||||
return filtered[_random.Next(filtered.Count)];
|
return GetWeightedRandom(filtered, weightPercentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. 随机取任意一个
|
// 1. 随机任意一个(排除默认)+ 百分比权重
|
||||||
public static ChineseTtsVoice GetRandomExclude()
|
public static ChineseTtsVoice GetRandomExclude(int weightPercentage = 80)
|
||||||
{
|
{
|
||||||
var all = Enum.GetValues(typeof(ChineseTtsVoice)).Cast<ChineseTtsVoice>().ToList();
|
var all = Enum.GetValues(typeof(ChineseTtsVoice)).Cast<ChineseTtsVoice>().ToList();
|
||||||
all = all.Where(f => f != DefaultFemale && f != DefaultMale).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);
|
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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,9 +62,25 @@ return Task.Run(() => serviceRequest.PostAsJsonAsync<AiBookData,AiBookData>("/
|
|||||||
{
|
{
|
||||||
var compositionData = new ProcessBookCompositionData3{
key = key,
encoding = encoding,
pattern = pattern };
return Task.Run(() => serviceRequest.PostAsJsonAsync<ProcessBookCompositionData3, AiBookData>("/AiBook/ProcessBook", compositionData)).GetAwaiter().GetResult(); }
|
var compositionData = new ProcessBookCompositionData3{
key = key,
encoding = encoding,
pattern = pattern };
return Task.Run(() => serviceRequest.PostAsJsonAsync<ProcessBookCompositionData3, AiBookData>("/AiBook/ProcessBook", compositionData)).GetAwaiter().GetResult(); }
|
||||||
|
|
||||||
public IActionResult GetTtsStream(string text)
|
public IActionResult GetMp3Stream(AiSentenceViewEntity aiSentence)
|
||||||
{
|
{
|
||||||
return Task.Run(() => serviceRequest.PostAsJsonAsync<IActionResult>("/AiBook/GetTtsStream?text=" + text.ToString())).GetAwaiter().GetResult(); }
|
return Task.Run(() => serviceRequest.PostAsJsonAsync<AiSentenceViewEntity,IActionResult>("/AiBook/GetMp3Stream" , aiSentence)).GetAwaiter().GetResult(); }
|
||||||
|
|
||||||
|
public void GenerateMp3(AiChapterEntity[] chapters)
|
||||||
|
{
|
||||||
|
Task.Run(() => serviceRequest.PostAsJsonAsync<AiChapterEntity[],dynamic>("/AiBook/GenerateMp3" , chapters)).GetAwaiter().GetResult(); }
|
||||||
|
|
||||||
|
public void GenerateMp3ByBookId(string bookId)
|
||||||
|
{
|
||||||
|
Task.Run(() => serviceRequest.PostAsync("/AiBook/GenerateMp3ByBookId?bookId=" + bookId.ToString())).GetAwaiter().GetResult(); }
|
||||||
|
|
||||||
|
public void PackPersonNameByBookId(string bookId)
|
||||||
|
{
|
||||||
|
Task.Run(() => serviceRequest.PostAsync("/AiBook/PackPersonNameByBookId?bookId=" + bookId.ToString())).GetAwaiter().GetResult(); }
|
||||||
|
|
||||||
|
public void PackPersonName(AiChapterEntity[] chapters)
|
||||||
|
{
|
||||||
|
Task.Run(() => serviceRequest.PostAsJsonAsync<AiChapterEntity[],dynamic>("/AiBook/PackPersonName" , chapters)).GetAwaiter().GetResult(); }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -202,12 +202,12 @@ this.aiBookService= aiBookService;
|
|||||||
|
|
||||||
[PermissionOperate(name: "AiBook", operate: "Find")]
|
[PermissionOperate(name: "AiBook", operate: "Find")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public dynamic GetTtsStream(string text)
|
public dynamic GetMp3Stream(AiSentenceViewEntity aiSentence)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var result = aiBookService.GetTtsStream(text);
|
var result = aiBookService.GetMp3Stream(aiSentence);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch (ValidatedException vex)
|
catch (ValidatedException vex)
|
||||||
@ -220,6 +220,82 @@ this.aiBookService= aiBookService;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PermissionOperate(name: "AiBook", operate: "Find")]
|
||||||
|
[HttpPost]
|
||||||
|
public dynamic GenerateMp3(AiChapterEntity[] chapters){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
aiBookService.GenerateMp3(chapters);
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
catch (ValidatedException vex)
|
||||||
|
{
|
||||||
|
return vex;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ServiceErrorException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[PermissionOperate(name: "AiBook", operate: "Find")]
|
||||||
|
[HttpPost]
|
||||||
|
public dynamic GenerateMp3ByBookId(string bookId){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
aiBookService.GenerateMp3ByBookId(bookId);
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
catch (ValidatedException vex)
|
||||||
|
{
|
||||||
|
return vex;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ServiceErrorException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[PermissionOperate(name: "AiBook", operate: "Find")]
|
||||||
|
[HttpPost]
|
||||||
|
public dynamic PackPersonNameByBookId(string bookId){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
aiBookService.PackPersonNameByBookId(bookId);
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
catch (ValidatedException vex)
|
||||||
|
{
|
||||||
|
return vex;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ServiceErrorException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[PermissionOperate(name: "AiBook", operate: "Find")]
|
||||||
|
[HttpPost]
|
||||||
|
public dynamic PackPersonName(AiChapterEntity[] chapters){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
aiBookService.PackPersonName(chapters);
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
catch (ValidatedException vex)
|
||||||
|
{
|
||||||
|
return vex;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ServiceErrorException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user