ow
This commit is contained in:
1 parent
5f222a23b3
commit
a71094cbf5
3 files changed
+134
-18
No files matched your search
+10
-18
@@ -30,6 +30,8 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
||||
|
||||
public void Run(Dictionary<string, string> bodyDict)
|
||||
{
|
||||
ConsoleOutput.HideStdError();
|
||||
|
||||
IRepository<AiSentenceViewEntity> repository = service.GetRepository<IRepository<AiSentenceViewEntity>>();
|
||||
|
||||
string bookId = string.Empty;
|
||||
@@ -64,13 +66,12 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
||||
.GroupBy(ent => new { ent.BookId, ent.ChapterId })
|
||||
.ToList();
|
||||
|
||||
int totalLines = chapterGroups.Count();
|
||||
int totalLines = ents.Count();
|
||||
int processedLines = 0; // 已处理行数计数器
|
||||
UpdateProgress(processedLines, totalLines);
|
||||
|
||||
foreach (var chapter in chapterGroups)
|
||||
{
|
||||
processedLines++;
|
||||
|
||||
string bookId = chapter.Key.BookId;
|
||||
int chapterId = chapter.Key.ChapterId;
|
||||
List<string> tempMp3List = new List<string>(); // 本章所有碎片音频
|
||||
@@ -78,6 +79,8 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
||||
// 2. 生成本章所有句子音频
|
||||
foreach (AiSentenceViewEntity ent in chapter)
|
||||
{
|
||||
processedLines++;
|
||||
|
||||
string voice = ChineseTtsVoice.Sherpa2.ToString();
|
||||
if (ent.DialogueIndc == YesNoPolicy.YES)
|
||||
{
|
||||
@@ -102,6 +105,8 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
||||
SaveAudioToFileHelper.AudioToFile(EnumHelper.ToEnum<ChineseTtsVoice>(voice), ent.Content, filePath);
|
||||
|
||||
tempMp3List.Add(filePath); // 加入合并列表
|
||||
|
||||
UpdateProgress(processedLines, totalLines);
|
||||
}
|
||||
|
||||
Thread.Sleep(100);
|
||||
@@ -118,8 +123,6 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
||||
try { File.Delete(chunk); } catch { }
|
||||
}
|
||||
|
||||
Console.WriteLine($"章节合并完成:{outputFileName}");
|
||||
|
||||
UpdateProgress(processedLines, totalLines);
|
||||
}
|
||||
}
|
||||
@@ -166,22 +169,11 @@ namespace CloudBuilder.Topshelf.Task.TTS
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"✅ 合并成功:{outputFilePath},大小:{new FileInfo(outputFilePath).Length} 字节");
|
||||
//Console.WriteLine($"✅ 合并成功:{outputFilePath},大小:{new FileInfo(outputFilePath).Length} 字节");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"❌ 合并失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助方法:WAV 转 MP3
|
||||
private void WaveFileToMp3(byte[] wavData, string mp3Path)
|
||||
{
|
||||
using (var ms = new MemoryStream(wavData))
|
||||
using (var waveReader = new WaveFileReader(ms))
|
||||
using (var mp3Writer = new LameMP3FileWriter(mp3Path, waveReader.WaveFormat, 128))
|
||||
{
|
||||
waveReader.CopyTo(mp3Writer);
|
||||
//Console.WriteLine($"❌ 合并失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user