43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using CloudBuilder.Core.DependencyInjection.Task;
|
|
using CloudBuilder.Topshelf.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace CloudBuilder.Topshelf.Task.TTS
|
|
{
|
|
//task:TtsTask voice:Sherpa2 save_path:D:\\Net8\\FileServer\\Backup\\DmsFile\\voice\\20260528112739.mp3 text:二愣子睁大着双眼,直直望着茅草和烂泥糊成的黑屋顶,身上盖着的旧棉被,已呈深黄色,看不出原来的本来面目,还若有若无的散发着淡淡的霉味。
|
|
public class TtsTask : IScheduleTask
|
|
{
|
|
private readonly IApplicationService service;
|
|
|
|
public TtsTask(IApplicationService service)
|
|
{
|
|
this.service = service;
|
|
}
|
|
|
|
public void Run(Dictionary<string, string> bodyDict)
|
|
{
|
|
string save_path = string.Empty, text = string.Empty, voice = ChineseTtsVoice.Sherpa2.ToString();
|
|
if (bodyDict.ContainsKey("voice"))
|
|
voice = bodyDict["voice"];
|
|
|
|
if (bodyDict.ContainsKey("save_path"))
|
|
save_path = bodyDict["save_path"];
|
|
|
|
if (bodyDict.ContainsKey("text"))
|
|
text = bodyDict["text"];
|
|
|
|
if (string.IsNullOrEmpty(voice) || string.IsNullOrEmpty(save_path) || string.IsNullOrEmpty(text)) return;
|
|
|
|
SaveAudioToFileHelper.AudioToFile(EnumHelper.ToEnum<ChineseTtsVoice>(voice), text, save_path);
|
|
}
|
|
}
|
|
}
|