From cb3fdca3e1830576ea9c083d2fd65096dbddc5a9 Mon Sep 17 00:00:00 2001 From: owenchen Date: Thu, 4 Jun 2026 08:16:37 +0800 Subject: [PATCH] ow --- .../AiBookOperationPage.Designer.cs | 17 +++- CloudBuilder.AI.Gui/AiBookOperationPage.cs | 49 ++++++++-- CloudBuilder.AI.Service/AiBookService.auto.cs | 96 +++++++++++++++++-- .../Entity/AiChapterPersonEntity.auto.cs | 29 +++--- .../Policy/ChineseTtsVoicePolicy.cs | 90 +++++++++++++---- .../Service/IAiBookService.auto.cs | 10 +- CloudBuilder.Request/AI/AiBookRequest.auto.cs | 20 +++- .../Controllers/Ai/AiBookController.auto.cs | 80 +++++++++++++++- 8 files changed, 339 insertions(+), 52 deletions(-) diff --git a/CloudBuilder.AI.Gui/AiBookOperationPage.Designer.cs b/CloudBuilder.AI.Gui/AiBookOperationPage.Designer.cs index 91f60d2..461cea2 100644 --- a/CloudBuilder.AI.Gui/AiBookOperationPage.Designer.cs +++ b/CloudBuilder.AI.Gui/AiBookOperationPage.Designer.cs @@ -82,6 +82,7 @@ namespace CloudBuilder.AI.Gui processBut = new Krypton.Toolkit.KryptonButton(); extractNamesBut = new Krypton.Toolkit.KryptonButton(); uploadBut = new Krypton.Toolkit.KryptonButton(); + generaterMp3But = new Krypton.Toolkit.KryptonButton(); kryptonPanel2 = new Krypton.Toolkit.KryptonPanel(); mainPanel = new TableLayoutPanel(); topPanel = new TableLayoutPanel(); @@ -614,16 +615,17 @@ namespace CloudBuilder.AI.Gui 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.Absolute, 80F)); + processPanel.ColumnStyles.Add(new ColumnStyle()); processPanel.Controls.Add(processBut, 1, 0); processPanel.Controls.Add(extractNamesBut, 2, 0); processPanel.Controls.Add(uploadBut, 0, 0); + processPanel.Controls.Add(generaterMp3But, 3, 0); processPanel.Location = new Point(377, 127); processPanel.Margin = new Padding(0); processPanel.Name = "processPanel"; processPanel.RowCount = 1; processPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); - processPanel.Size = new Size(356, 31); + processPanel.Size = new Size(373, 31); processPanel.TabIndex = 6; // // processBut @@ -656,6 +658,16 @@ namespace CloudBuilder.AI.Gui uploadBut.Values.Text = "上传"; 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.Dock = DockStyle.Fill; @@ -979,5 +991,6 @@ namespace CloudBuilder.AI.Gui private Krypton.Toolkit.KryptonDataGridViewTextBoxColumn genderCol; private Krypton.Toolkit.KryptonDataGridViewTextBoxColumn sentimentCol; private Krypton.Toolkit.KryptonDataGridViewComboBoxColumn sentenceStatusCol; + private Krypton.Toolkit.KryptonButton generaterMp3But; } } diff --git a/CloudBuilder.AI.Gui/AiBookOperationPage.cs b/CloudBuilder.AI.Gui/AiBookOperationPage.cs index 3dbc5b0..77dcad7 100644 --- a/CloudBuilder.AI.Gui/AiBookOperationPage.cs +++ b/CloudBuilder.AI.Gui/AiBookOperationPage.cs @@ -780,13 +780,12 @@ namespace CloudBuilder.AI.Gui return; } - AiChapterEntity chapter = dataGv.GetRowData(dataGv.SelectedCells[0].RowIndex); + AiChapterEntity[] chapters = dataGv.GetSelectedRowsData(); - //aiBookRequest.ExtractNamesByChapterGuid(data.AiBook.BookId, chapter.ChapterId); - - AiSentenceViewEntity[] aiSentences = aiSentenceRequest.FindByChapterId(chapter.ChapterId); - - sentenceGv.SetDataSource(aiSentences); + if (chapters != null) + aiBookRequest.PackPersonName(chapters); + else + aiBookRequest.PackPersonNameByBookId(data.AiBook.BookId); ShowMessageBox.ShowInfo(securityMessagePolicy.ComposeMessage(SecurityMessagePolicy.GUI_SUCCEED_UPDATED_NULL)); @@ -819,7 +818,7 @@ namespace CloudBuilder.AI.Gui AiSentenceViewEntity sentence = sentenceGv.GetRowData(sentenceGv.SelectedCells[0].RowIndex); - using (Stream audioStream = ServiceHelper.GetService()!.PostStreamAsync("/AiBook/GetTtsStream?text=" + sentence.Content, null, string.Empty).GetAwaiter().GetResult()) + using (Stream audioStream = ServiceHelper.GetService()!.PostStreamAsync("/AiBook/GetMp3Stream", null, sentence).GetAwaiter().GetResult()) { PlayMp3Stream(audioStream); } @@ -915,5 +914,41 @@ namespace CloudBuilder.AI.Gui 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(); + + 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); + } + } } } diff --git a/CloudBuilder.AI.Service/AiBookService.auto.cs b/CloudBuilder.AI.Service/AiBookService.auto.cs index b3c6861..76db8ec 100644 --- a/CloudBuilder.AI.Service/AiBookService.auto.cs +++ b/CloudBuilder.AI.Service/AiBookService.auto.cs @@ -19,6 +19,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using System.Diagnostics.Contracts; using System.IO; +using System.Net; using System.Text; using System.Transactions; namespace CloudBuilder.AI.Service @@ -250,13 +251,24 @@ namespace CloudBuilder.AI.Service } - [PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Find)] - public IActionResult GetTtsStream(string text) - { - string fileDownloadName = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice", DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3"); + //public IActionResult GetTtsStream(string text) + //{ + // string fileDownloadName = Path.Combine(service.Configuration["FileServiceSettings:BackupDmsFileDirectory"], @"voice", DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3"); - string param = PackParameters(ChineseTtsVoice.Sherpa2.ToString(), fileDownloadName, text); - RunMyProcess(service.Configuration["CloudBuilder.Topshelf:Path"], param); + // string param = PackParameters(ChineseTtsVoice.Sherpa2.ToString(), fileDownloadName, text); + // 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); @@ -264,13 +276,81 @@ namespace CloudBuilder.AI.Service 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 repositoryAiChapterEntity = repository.GetRepository>(); + 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 repositoryAiChapterEntity = repository.GetRepository>(); + 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 para = new List(); + 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 para = new List(); para.Add("task:" + "TtsTask"); + para.Add("book_id:" + bookId); + para.Add("chapter_id:" + chapterId); para.Add("voice:" + voice); para.Add("save_path:" + save_path); - para.Add("text:" + text.Replace(":", ":")); + para.Add("speed:1"); + para.Add("actor:NA"); return para.ToArray().ToDelimiteredList(' '); } diff --git a/CloudBuilder.AI/Entity/AiChapterPersonEntity.auto.cs b/CloudBuilder.AI/Entity/AiChapterPersonEntity.auto.cs index a2b3806..2b02f7d 100644 --- a/CloudBuilder.AI/Entity/AiChapterPersonEntity.auto.cs +++ b/CloudBuilder.AI/Entity/AiChapterPersonEntity.auto.cs @@ -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; } } diff --git a/CloudBuilder.AI/Policy/ChineseTtsVoicePolicy.cs b/CloudBuilder.AI/Policy/ChineseTtsVoicePolicy.cs index 6df6819..65bbc14 100644 --- a/CloudBuilder.AI/Policy/ChineseTtsVoicePolicy.cs +++ b/CloudBuilder.AI/Policy/ChineseTtsVoicePolicy.cs @@ -168,45 +168,99 @@ namespace CloudBuilder.AI.Policy ChineseTtsVoice.Theresa }; - // 1. 随机取任意一个 - public static ChineseTtsVoice GetRandom() + + /// + /// 百分比越大,取前面5个的机会越大 + /// + /// 0~100,推荐 50~100 + /// + /// 百分比越大,取前面5个的机会越大 + /// + /// 0~100,越大越容易选前5个 + public static ChineseTtsVoice GetRandom(int percentage = 80) { var all = Enum.GetValues(typeof(ChineseTtsVoice)).Cast().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().ToList(); all = all.Where(f => f != DefaultFemale && f != DefaultMale).ToList(); - return all[_random.Next(all.Count)]; + return GetWeightedRandom(all, weightPercentage); + } + + /// + /// 加权随机:百分比越高,前5个概率越大 + /// + private static ChineseTtsVoice GetWeightedRandom(List 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)]; } } } diff --git a/CloudBuilder.AI/Service/IAiBookService.auto.cs b/CloudBuilder.AI/Service/IAiBookService.auto.cs index 3486b26..c81e3d7 100644 --- a/CloudBuilder.AI/Service/IAiBookService.auto.cs +++ b/CloudBuilder.AI/Service/IAiBookService.auto.cs @@ -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); + + } } diff --git a/CloudBuilder.Request/AI/AiBookRequest.auto.cs b/CloudBuilder.Request/AI/AiBookRequest.auto.cs index 399b06a..32d6a43 100644 --- a/CloudBuilder.Request/AI/AiBookRequest.auto.cs +++ b/CloudBuilder.Request/AI/AiBookRequest.auto.cs @@ -62,9 +62,25 @@ return Task.Run(() => serviceRequest.PostAsJsonAsync("/ { var compositionData = new ProcessBookCompositionData3{ key = key, encoding = encoding, pattern = pattern }; return Task.Run(() => serviceRequest.PostAsJsonAsync("/AiBook/ProcessBook", compositionData)).GetAwaiter().GetResult(); } - public IActionResult GetTtsStream(string text) + public IActionResult GetMp3Stream(AiSentenceViewEntity aiSentence) { -return Task.Run(() => serviceRequest.PostAsJsonAsync("/AiBook/GetTtsStream?text=" + text.ToString())).GetAwaiter().GetResult(); } +return Task.Run(() => serviceRequest.PostAsJsonAsync("/AiBook/GetMp3Stream" , aiSentence)).GetAwaiter().GetResult(); } + + public void GenerateMp3(AiChapterEntity[] chapters) + { + Task.Run(() => serviceRequest.PostAsJsonAsync("/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("/AiBook/PackPersonName" , chapters)).GetAwaiter().GetResult(); } } diff --git a/CloudBuilder.Web.Entry/Controllers/Ai/AiBookController.auto.cs b/CloudBuilder.Web.Entry/Controllers/Ai/AiBookController.auto.cs index e072e3a..9e5339c 100644 --- a/CloudBuilder.Web.Entry/Controllers/Ai/AiBookController.auto.cs +++ b/CloudBuilder.Web.Entry/Controllers/Ai/AiBookController.auto.cs @@ -202,12 +202,12 @@ this.aiBookService= aiBookService; [PermissionOperate(name: "AiBook", operate: "Find")] [HttpPost] - public dynamic GetTtsStream(string text) + public dynamic GetMp3Stream(AiSentenceViewEntity aiSentence) { try { - var result = aiBookService.GetTtsStream(text); + var result = aiBookService.GetMp3Stream(aiSentence); return result; } 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); + } + } + } } \ No newline at end of file