百度语音合成调用DEMO

百度语音合成,没有粤语,只得放弃。
讯飞的粤语包太贵,第二年收费2万,只好选择阿里。

//百度语音合成调用DEMO
public class BaiduVoice { // 设置APPID/AK/SK public string APP_ID = "<Your App ID>"; public string API_KEY = "<Your API Key>"; public string SECRET_KEY = "<Your Secret Key>"; public void Play(string text) { if (!Directory.Exists(@"d:\temp")) { Directory.CreateDirectory(@"d:\temp"); } var client = new Baidu.Aip.Speech.Tts(API_KEY, SECRET_KEY); client.Timeout = 60000;  // 修改超时时间 // 可选参数 var option = new Dictionary<string, object>() { {"spd", 4}, // 语速 {"vol", 5}, // 音量 {"per", 2 }  // 发音人,4:情感度丫丫童声 }; //var result = client.Synthesis("请注意,请张三到四号窗口办理业务,谢谢", option); var result = client.Synthesis(text, option); if (result.ErrorCode == 0)  // 或 result.Success { string fileName = $@"d:\temp\{Guid.NewGuid()}.mp3"; File.WriteAllBytes(fileName, result.Data); Mp3Player mp3Play = new Mp3Player() { FileName = fileName, }; mp3Play.play(); } else { MsgBox.Show(JsonConvert.SerializeObject(result)); } } }
posted @   深圳大漠  阅读(262)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2013-12-20 C#4语法
点击右上角即可分享
微信分享提示