Beispiel #1
0
        // 开始合成按钮(语音合成功能)
        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();
        }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="options"></param>
 /// <param name="runtime"></param>
 /// <param name="logger"></param>
 public BaiduSynthesizerProvider(IOptionsMonitor <BaiduSpeechOption> options, IJSRuntime runtime, ILogger <BaiduSynthesizerProvider> logger)
 {
     JSRuntime    = runtime;
     SpeechOption = options.CurrentValue;
     Client       = new Baidu.Aip.Speech.Tts(SpeechOption.ApiKey, SpeechOption.Secret);
     Logger       = logger;
 }
Beispiel #3
0
        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("语音合成失败");
        }
Beispiel #4
0
        // 开始合成按钮(语音合成功能)
        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();
        }
Beispiel #5
0
        public static Tts GetClient()
        {
            var apiKey    = ConfigurationManager.AppSettings["API_KEY"];
            var appId     = ConfigurationManager.AppSettings["APP_ID"];
            var secretKey = ConfigurationManager.AppSettings["SECRET_KEY"];

            var client = new Baidu.Aip.Speech.Tts(apiKey, secretKey);

            client.Timeout = 60000;  // 修改超时时间

            client.AppId = appId;
            return(client);
        }
Beispiel #6
0
        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);
        }
 public BaiduSpeech()
 {
     client = new Baidu.Aip.Speech.Tts(API_KEY, SECRET_KEY);
 }