This commit is contained in:
owenchen committed 2026-05-28 15:05:46 +08:00
1 parent e60118eb53
commit 2e990e687f
38 files changed
+441 -237

No files matched your search

+76 -2
View File
@@ -1,4 +1,5 @@
using CloudBuilder.AI.Data;
using CliWrap;
using CloudBuilder.AI.Data;
using CloudBuilder.AI.Entity;
using CloudBuilder.AI.Policy;
using CloudBuilder.AI.SearchCriteria;
@@ -14,8 +15,10 @@ using CloudBuilder.Security.Utility;
using DocumentFormat.OpenXml.ExtendedProperties;
using DocumentFormat.OpenXml.Presentation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.Contracts;
using System.IO;
using System.Text;
using System.Transactions;
namespace CloudBuilder.AI.Service
@@ -291,7 +294,7 @@ namespace CloudBuilder.AI.Service
foreach (var name in names)
{
entity = new AiChapterPersonEntity();
entity.Guid= Guid.NewGuid().ToString();
entity.Guid = Guid.NewGuid().ToString();
entity.ChapterGuid = paragraph.ChapterGuid;
entity.ParagraphGuid = paragraph.Guid;
entity.ParagraphIndex = paragraph.ParagraphIndex;
@@ -304,5 +307,76 @@ namespace CloudBuilder.AI.Service
if (aiChapterPersonEntities != null && aiChapterPersonEntities.Count() > 0)
repositoryAiChapterPersonEntity.InsertNow(aiChapterPersonEntities);
}
[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");
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 };
}
private string PackParameters(string voice, string save_path, string text)
{
List<string> para = new List<string>();
para.Add("task:" + "TtsTask");
para.Add("voice:" + voice);
para.Add("save_path:" + save_path);
para.Add("text:" + text.Replace(":", ":"));
return para.ToArray().ToDelimiteredList(' ');
}
/// <summary>
/// 执行cmd指令(同步等待,await要求等待返回,转码太耗时)
/// </summary>
/// <param name="Parameters"></param>
public void RunMyProcess(string exePath, string Parameters)
{
try
{
if (string.IsNullOrEmpty(exePath)) return;
var result = Cli.Wrap(exePath)
.WithWorkingDirectory(Path.GetDirectoryName(exePath))
.WithArguments(Parameters)
.ExecuteAsync().GetAwaiter().GetResult();
Thread.Sleep(300);
}
catch (Exception ex)
{
throw new ValidatedException(ex.Message);
}
}
/// <summary>
/// 执行cmd指令(异步不等待,await要求等待返回,转码太耗时)
/// </summary>
/// <param name="Parameters"></param>
public void RunMyProcessAsync(string exePath, string Parameters)
{
try
{
if (string.IsNullOrEmpty(exePath)) return;
Cli.Wrap(exePath)
.WithWorkingDirectory(Path.GetDirectoryName(exePath))
.WithArguments(Parameters)
.ExecuteAsync();
Thread.Sleep(300);
}
catch (Exception ex)
{
throw new ValidatedException(ex.Message);
}
}
}
}