43 lines
1.5 KiB
C#
43 lines
1.5 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:\MAFAI\cc.wav 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);
|
|
}
|
|
}
|
|
}
|