百度語音合成,沒有粵語,只得放棄。
訊飛的粵語包太貴,第二年收費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));
}
}
}