百度语音合成调用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 @ 2020-12-20 10:48  深圳大漠  阅读(241)  评论(0编辑  收藏  举报