1 Star 1 Fork 1

okay6/paddlepaddle-model

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bai2.py 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
coding666 提交于 2018-07-24 13:00 . Add files via upload
#encoding:utf-8
import requests
import json
import uuid
import base64
def get_token():
url = "https://openapi.baidu.com/oauth/2.0/token"
grant_type = "client_credentials"
api_key = "f2qgYOAj2vk3Dqdd4ADV6dWB" # 自己申请的应用
secret_key = "0sj87GtzqmsCTK6gYG5Ne4rRn3mGL3ql" # 自己申请的应用
data = {'grant_type': 'client_credentials', 'client_id': api_key, 'client_secret': secret_key}
r = requests.post(url, data=data)
token = json.loads(r.text).get("access_token")
return token
def recognize(sig, rate, token):
url = "http://vop.baidu.com/server_api"
speech_length = len(sig)
speech = base64.b64encode(sig).decode("utf-8")
mac_address = uuid.UUID(int=uuid.getnode()).hex[-12:]
rate = rate
data = {
"format": "wav",
"lan": "zh",
"token": token,
"len": speech_length,
"rate": rate,
"speech": speech,
"cuid": mac_address,
"channel": 1,
}
data_length = len(json.dumps(data).encode("utf-8"))
headers = {"Content-Type": "application/json",
"Content-Length": data_length}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r.text)
filename = "01.wav"
signal = open(filename, "rb").read()
rate = 8000
token = get_token()
recognize(signal, rate, token)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/okay_6/paddlepaddle-model.git
git@gitee.com:okay_6/paddlepaddle-model.git
okay_6
paddlepaddle-model
paddlepaddle-model
master

搜索帮助