python实现百度语音之语音识别

这篇文字是基于前辈分享的基础上写出来的。
前辈在这里:
http://blog.sina.com.cn/s/blog_7cedb56d0102vb5p.html
http://blog.csdn.net/wolfblood_zzx/article/details/46418635
http://blog.csdn.net/happen23/article/details/45821697

我这里只使用了requests库,相对来说简单点:

#-*- coding: utf-8 -*-
import base64, requests
d = open('testxf.pcm', 'rb').read()
data = {
    "format": "pcm",
    # "format": "wav",
    "rate": 16000,
    "channel": 1,
    "token": "your token",
    "cuid": "your mac",
    "len": len(d),
    "speech": base64.encodestring(d).replace('\n', '')
}
result = requests.post('http://vop.baidu.com/server_api', json=data, headers={'Content-Type': 'application/json'})
data_result = result.json()
print data_result['err_msg']
if data_result['err_msg']=='success.':
    print "语音结果:" + data_result['result'][0].encode('utf-8')
else:
    print data_result

这里获取TOKEN的代码,就没贴出来了,可以参考前辈的代码。
特别注意:”speech”: base64.encodestring(d).replace(‘\n’, ”),这也是参考一位前辈的指导,需要去掉最后的回车(不好意思没记住前辈的地址)。
另外,我测试了2个自己的WAV文件,清晰的可以识别,噪音比较大的识别不了。后面研究下降噪,看能不能识别出来。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值