爬虫tesserocr识别验证码及百度api语音接口 使用案例
一.百度语音api1.先注册 地址:http://ai.baidu.com/?track=cp:ainsem|pf:pc|pp:tongyong-pinpai|pu:pinpai-baiduAIkaifangpingtai|ci:|kw:100038172.下载百度语音识别python sdk详情见:http://ai.baidu.com/docs#/ASR-Online-Python-...
·
一.百度语音api
1.先注册 地址:http://ai.baidu.com/?track=cp:ainsem|pf:pc|pp:tongyong-pinpai|pu:pinpai-baiduAIkaifangpingtai|ci:|kw:10003817
2.下载百度语音识别python sdk 详情见:http://ai.baidu.com/docs#/ASR-Online-Python-SDK/top
3.在百度控制台里创建应用,获取app_id api_key 以及 secret_key
3.语音识别使用模板
#百度aip接口使用模板,
from aip import AipSpeech
from PIL import Image
app_id = "xxxxxx"
api_key = "xxxxxxxxxxxxxxxxxxxxxxxx"
secret_key = "xxxxxxxxxxxxxxxxxxxxxxxx"
client = AipSpeech(app_id, api_key, secret_key)
#1为女生,0是男生
result = client.synthesis("川好帅呀!爱你么么哒!", "zh", 1, {
"vol": 9, # 音量0-15
"spd": 6, # 语速0-9
"pit": 7, # 语调0-9
"per": 4, # 音色0-9
})
#格式要为mp3语音文件
with open("audio.mp3", "wb") as f:
f.write(result)
二.tesserocr识别爬虫中的简单验证码代码模板
过程:1.获取验证码图片
2.保存验证码
3.打开验证码
4.识别验证码
#获得验证码
r=requests.get(image_url)
path='1.png'
#保存验证码
with open(path,'wb') as f:
f.write(r2.content)
f.close()
#打开验证码
image=Image.open(path)
#识别验证码
result =tesserocr.image_to_text(image)
文章作者:张川
作者QQ:468336329
备注:本文纯属原创,未经同意请勿转载。
更多推荐
所有评论(0)