ow
This commit is contained in:
parent
2c6475b2d5
commit
5fe7c6260e
Binary file not shown.
Binary file not shown.
@ -22,10 +22,19 @@ namespace CloudBuilder.Topshelf.Python
|
|||||||
if (!File.Exists(file)) return;
|
if (!File.Exists(file)) return;
|
||||||
|
|
||||||
string init = File.ReadAllText(file, Encoding.UTF8);
|
string init = File.ReadAllText(file, Encoding.UTF8);
|
||||||
|
File.AppendAllText("log.txt", "SoVITS:" + file + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
python.Exec(init);
|
try
|
||||||
|
{
|
||||||
|
python.Exec(init);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
File.AppendAllText("log.txt", "SoVITS-Exec:" + ex.Message + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
File.AppendAllText("log.txt", "SoVITS-Exec:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,13 +28,14 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
|||||||
|
|
||||||
public SoVITSTtsTask(IApplicationService service)
|
public SoVITSTtsTask(IApplicationService service)
|
||||||
{
|
{
|
||||||
|
File.AppendAllText("log.txt", "SoVITSTtsTask:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run(Dictionary<string, string> bodyDict)
|
public void Run(Dictionary<string, string> bodyDict)
|
||||||
{
|
{
|
||||||
|
File.AppendAllText("log.txt", "Run:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
ConsoleOutput.HideStdError();
|
ConsoleOutput.HideStdError();
|
||||||
|
|
||||||
IRepository<AiSentenceViewEntity> repository = service.GetRepository<IRepository<AiSentenceViewEntity>>();
|
IRepository<AiSentenceViewEntity> repository = service.GetRepository<IRepository<AiSentenceViewEntity>>();
|
||||||
|
|
||||||
string bookId = string.Empty;
|
string bookId = string.Empty;
|
||||||
@ -58,9 +59,8 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
|||||||
&& (string.IsNullOrEmpty(from_chapter_id) || x.ChapterId >= Convert.ToInt32(from_chapter_id))
|
&& (string.IsNullOrEmpty(from_chapter_id) || x.ChapterId >= Convert.ToInt32(from_chapter_id))
|
||||||
&& (string.IsNullOrEmpty(to_chapter_id) || x.ChapterId <= Convert.ToInt32(to_chapter_id)
|
&& (string.IsNullOrEmpty(to_chapter_id) || x.ChapterId <= Convert.ToInt32(to_chapter_id)
|
||||||
)).OrderBy(x => x.ChapterId).ThenBy(x => x.ParagraphId).ThenBy(x => x.SentenceIndex).ToArray();
|
)).OrderBy(x => x.ChapterId).ThenBy(x => x.ParagraphId).ThenBy(x => x.SentenceIndex).ToArray();
|
||||||
|
|
||||||
if (ents == null || ents.Length == 0) return;
|
if (ents == null || ents.Length == 0) return;
|
||||||
|
File.AppendAllText("log.txt", "SoVITSTtsVoiceRandom:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
string save_path = string.Empty, text = string.Empty, voice = SoVITSTtsVoiceRandom.GetRandomYoungFemale().ToString(), actor = string.Empty, actor_voice = SoVITSTtsVoiceRandom.GetRandomYoungMale().ToString();
|
string save_path = string.Empty, text = string.Empty, voice = SoVITSTtsVoiceRandom.GetRandomYoungFemale().ToString(), actor = string.Empty, actor_voice = SoVITSTtsVoiceRandom.GetRandomYoungMale().ToString();
|
||||||
if (bodyDict.ContainsKey("actor"))
|
if (bodyDict.ContainsKey("actor"))
|
||||||
actor = bodyDict["actor"];
|
actor = bodyDict["actor"];
|
||||||
@ -78,18 +78,23 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
|||||||
|
|
||||||
if (bodyDict.ContainsKey("speed"))
|
if (bodyDict.ContainsKey("speed"))
|
||||||
speed = Convert.ToSingle(bodyDict["speed"]);
|
speed = Convert.ToSingle(bodyDict["speed"]);
|
||||||
|
File.AppendAllText("log.txt", "GenerateAndMergeChapterAudio:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
GenerateAndMergeChapterAudio(ents, speed, actor, actor_voice, voice, save_path);
|
GenerateAndMergeChapterAudio(ents, speed, actor, actor_voice, voice, save_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GenerateAndMergeChapterAudio(AiSentenceViewEntity[] ents, float speed, string actor, string actor_voice, string mainVoice, string save_path)
|
public void GenerateAndMergeChapterAudio(AiSentenceViewEntity[] ents, float speed, string actor, string actor_voice, string mainVoice, string save_path)
|
||||||
{
|
{
|
||||||
IRepository<AiBookPersonEntity> repositoryAiBookPersonEntity = service.GetRepository<IRepository<AiBookPersonEntity>>();
|
IRepository<AiBookPersonEntity> repositoryAiBookPersonEntity = service.GetRepository<IRepository<AiBookPersonEntity>>();
|
||||||
|
File.AppendAllText("log.txt", "BookId:" + ents[0].BookId + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
|
|
||||||
AiBookPersonEntity[] bps = repositoryAiBookPersonEntity.DetachedEntities.Where(x => x.BookId == ents[0].BookId).ToArray();
|
AiBookPersonEntity[] bps = repositoryAiBookPersonEntity.DetachedEntities.Where(x => x.BookId == ents[0].BookId).ToArray();
|
||||||
|
|
||||||
|
File.AppendAllText("log.txt", "repositoryAiBookPersonEntity:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
|
|
||||||
Python39Command python39Command = new Python39Command(service);
|
Python39Command python39Command = new Python39Command(service);
|
||||||
|
File.AppendAllText("log.txt", "Python39Command:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
SoVITS soVITS = new SoVITS(python39Command);
|
SoVITS soVITS = new SoVITS(python39Command);
|
||||||
|
File.AppendAllText("log.txt", "SoVITS:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
// 1. 按 BookId + ChapterId 分组(关键!)
|
// 1. 按 BookId + ChapterId 分组(关键!)
|
||||||
var chapterGroups = ents
|
var chapterGroups = ents
|
||||||
.Where(ent => ent.Content.Any(c => c >= 0x4E00 && c <= 0x9FFF)) // 只保留含中文的句子
|
.Where(ent => ent.Content.Any(c => c >= 0x4E00 && c <= 0x9FFF)) // 只保留含中文的句子
|
||||||
@ -179,6 +184,7 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
|||||||
string fileName = string.Format("{0}_{1}_{2}_{3}.mp3", ent.BookId, ent.ChapterId, ent.ParagraphId, ent.SentenceId);
|
string fileName = string.Format("{0}_{1}_{2}_{3}.mp3", ent.BookId, ent.ChapterId, ent.ParagraphId, ent.SentenceId);
|
||||||
string filePath = Path.Combine(save_path, fileName);
|
string filePath = Path.Combine(save_path, fileName);
|
||||||
|
|
||||||
|
File.AppendAllText("log.txt", "Generate:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
|
||||||
// 生成音频
|
// 生成音频
|
||||||
soVITS.Generate(ent.Content, soVITS.Voices[EnumHelper.ToEnum<SoVITSTtsVoice>(voice)], filePath);
|
soVITS.Generate(ent.Content, soVITS.Voices[EnumHelper.ToEnum<SoVITSTtsVoice>(voice)], filePath);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user