This commit is contained in:
owenchen committed 2026-06-04 08:16:37 +08:00
1 parent fd48c2eb7d
commit cb3fdca3e1
8 files changed
+339 -52

No files matched your search

+88 -8
View File
@@ -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<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>();
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(' ');
}