from aip import AipSpeech APP_ID = '15422825' APP_KEY = 'DhXGtWHYMujMVZZGRI3a7rzb' SECRET_KEY = 'PbyUvTL31fImGthOOIP5ZbbtEOGwGOoT' # 与百度进行一次加密校验,认证你是合法用户合法的应用 # AipSpeech是百度语音的客户端,认证成功之后,客户端将被开启,这里的client就是已经开启的百度语音的客户端了 client = AipSpeech(APP_ID,APP_KEY,SECRET_KEY) str = '今天天气怎么样?' result = client.synthesis(str, 'zh', 1, { 'vol':5, 'spd':3, 'pit':7, 'per':4 }) # 如果上面的三个参数APP_ID,APP_KEY,SECRET_KEY填写正确的话 # result就是音频文件的二进制文件流,如果返回失败的话,result就会是个字典 print(result) if not isinstance(result,dict): with open('audio.mp3','wb') as f: f.write(result) # 识别正确返回语音二进制文件流,错误则返回dict,参照下面错误代码. """ result = { 'err_detail': 'Tex length exceeds limit.', 'err_msg': 'parameter error.', 'err_no': 501, 'err_subcode': 10, 'tts_logid': 3257246120 } """
人工智能-baidu-aip语音合成(文字转语音)
猜你喜欢
转载自www.cnblogs.com/apollo1616/p/10271832.html
今日推荐
周排行