语音识别和文字转语音(基于百度AI)
花了一天时间,直接上代码 语音识别 #Author:Alex.Zhang import os import requests import json import base64 #首先配置必要的信息 baidu_server = 'https://aip.baidubce.com/oauth/2.0/token?' grant_type = 'client_credentials' client_id = 'umuduD7RyyO7OIsAGWHyuZeG' #API KEY client_secret = 'ay0ih0NhwAInGCgIdpmbvSG9nbl0KEw3' #Secret KEY #合成请求token的url url = baidu_server+'grant_type='+grant_type+'&client_id='+client_id+'&client_secret='+client_secret #获取token res = requests.get(url).text data = json.loads(res) token = data['access_token'] #设置音频的属性,采样率,格式等 VOICE_RATE = 16000 FILE_NAME = '666.wav' USER_ID = 'Xu.zh' #这里的id随便填填就好啦