public string Tts(string key, string text) { string path = voiceCacheFloder + "/" + key + ".mp3"; if (!Directory.Exists(voiceCacheFloder)) { Directory.CreateDirectory(voiceCacheFloder); } if (File.Exists(path)) { return(path); } Tts _ttsClient = new Baidu.Aip.Speech.Tts(API_KEY, SECRET_KEY); // 可选参数 var option = new Dictionary <string, object>() { { "spd", 5 }, // 语速 { "vol", 7 }, // 音量 { "per", 1 } // 发音人,4:情感度丫丫童声 }; var result = _ttsClient.Synthesis(text, option); if (result.ErrorCode == 0) // 或 result.Success { File.WriteAllBytes(path, result.Data); return(path); } throw new IOException("语音合成失败"); }
// 开始合成按钮(语音合成功能) private void synthesisButton_Click(object sender, EventArgs e) { String APP_ID = "16608219"; String API_KEY = "rjeInGuw5u1Y7hrY9he7rUw3"; String SECRET_KEY = "4RPxz8yC63i3puZNVC93ZqFCtiw5n16G"; // 获取输入框的值 String value = this.Speech_Synthesis.Text; // 将 value 转成语音文件存放到本地 var client = new Baidu.Aip.Speech.Tts(API_KEY, SECRET_KEY); // 可选参数 var option = new Dictionary <string, object>() { { "spd", 3 }, // 语速 { "vol", 7 }, // 音量 { "per", 4 } // 发音人,4:情感度丫丫童声 }; var result = client.Synthesis(value, option); try { if (result.ErrorCode == 0) { // 或 result.Success File.WriteAllBytes(@"C:\Users\sunwei\Desktop\1.mp3", result.Data); } } catch (Exception ex) { Console.Write(ex.StackTrace); } Play(); }
// 开始合成按钮(语音合成功能) private void synthesisButton_Click(object sender, EventArgs e) { String APP_ID = "14433392"; String API_KEY = "C7WMYgLeWv3Wm2yogwv5gD08"; String SECRET_KEY = "xcvwiwikALBDBaIcGisNQ6aQImtj3qua"; // 获取输入框的值 String value = this.Speech_Synthesis.Text; // 将 value 转成语音文件存放到本地 var client = new Baidu.Aip.Speech.Tts(API_KEY, SECRET_KEY); // 可选参数 var option = new Dictionary <string, object>() { { "spd", 3 }, // 语速 { "vol", 7 }, // 音量 { "per", 4 } // 发音人,4:情感度丫丫童声 }; var result = client.Synthesis(value, option); try { if (result.ErrorCode == 0) // 或 result.Success { File.WriteAllBytes("E:/doctorM/机器人-英语学习材料/48音标对应单词图片和音频/单词/1.mp3", result.Data); } } catch (Exception ex) { Console.Write(ex.StackTrace); } Play(); }
public string Tts(string textinput) { var options = new Dictionary <string, object>() { { "spd", 5 }, { "vol", 6 }, { "per", 4 } }; var result = client.Synthesis(textinput, options); if (result.ErrorCode == 0) { string path = randomName.Next().ToString() + ".mp3"; File.WriteAllBytes(path, result.Data); return(path); } else { return(string.Empty); } }
public static byte[] GetAudio(string text) { var tts = new Baidu.Aip.Speech.Tts(BaiduApiAppSetting.TextToAudioAppId, BaiduApiAppSetting.TextToAudioSecret); string cuid = BaiduApiAppSetting.TextToAudioCUID; var option = new Dictionary <string, object>() { { "cuid", cuid }, { "ctp", 1 }, //客户端类型选择,web端填写固定值1 { "lan", BaiduApiAppSetting.Language }, //固定值zh。语言选择,目前只有中英文混合模式,填写固定值zh { "spd", BaiduApiAppSetting.Speed }, //语速,取值0-15,默认为5中语速 { "pit", BaiduApiAppSetting.Pitch }, //音调,取值0-15,默认为5中语调 { "vol", BaiduApiAppSetting.Volume }, //音量,取值0-15,默认为5中音量 { "per", BaiduApiAppSetting.Pronunciation }, //(基础音库)度小宇=1,度小美=0,度逍遥=3,度丫丫=4 (精品音库)度博文=106,度小童=110,度小萌=111,度米朵=103,度小娇=5 { "aue", 3 } //mp3格式 }; var temp = tts.Synthesis(text, option); if (!temp.Success) { throw new AbhsException(ErrorCodeEnum.BaiduSpeechError, AbhsErrorMsg.ConstBaiduSpeechError); } return(temp.Data); }