1. 程式人生 > 實用技巧 >百度語音合成呼叫DEMO

百度語音合成呼叫DEMO

百度語音合成,沒有粵語,只得放棄。
訊飛的粵語包太貴,第二年收費2萬,只好選擇阿里。

//百度語音合成呼叫DEMO
publicclassBaiduVoice { //設定APPID/AK/SK publicstringAPP_ID="<Your App ID>"; publicstringAPI_KEY="<Your API Key>"; publicstringSECRET_KEY="<Your Secret Key>"; publicvoidPlay(stringtext) { if(!Directory.Exists(@"d:\temp")) { Directory.CreateDirectory(@"d:\temp"); } varclient=newBaidu.Aip.Speech.Tts(API_KEY,SECRET_KEY); client.Timeout=60000;//修改超時時間 //可選引數 varoption=newDictionary<string,object>() { {"spd",4},//語速 {"vol",5},//音量 {"per",2}//發音人,4:情感度丫丫童聲 }; //varresult=client.Synthesis("請注意,請張三到四號視窗辦理業務,謝謝",option); varresult=client.Synthesis(text,option); if(result.ErrorCode==0)//或result.Success { stringfileName=$@"d:\temp\{Guid.NewGuid()}.mp3"; File.WriteAllBytes(fileName,result.Data); Mp3Playermp3Play=newMp3Player() { FileName=fileName, }; mp3Play.play(); } else { MsgBox.Show(JsonConvert.SerializeObject(result)); } } }