随着地摊经济的火热,炒热,各种地摊相关的东西也开始出现,也愈发流行,比如地摊秘笈,地摊叫卖语音,而各种在线ai语音转换也开始出现,不太清楚是调用的哪个接口,比如下面这个网站,文本内容在线语音合成,高大上的ai转换,哈哈,其实是一个简单POST方式提交数据。
不过在测试当中,也发现了反爬,竟然是开启了宝塔的人机验证,重新抓包获取cookies及发包参数_token可解决!
POST入口
POST协议及参数
运行效果
附源码:
#http://www.zaixianai.cn/voiceCompose
#20200608 by WX:huguo00289
# -*- coding: utf-8 -*-
from fake_useragent import UserAgent
import requests,re,time
def ai(text):
ua=UserAgent()
headers={
'Cookie': 'Hm_lvt_d09fdf7e91f77cddf85908f081d4a3bc=1591423253,1591595218,1591595259; XSRF-TOKEN=eyJpdiI6InBYRDBUUTZVa0NcL0hwRDdYY05haERBPT0iLCJ2YWx1ZSI6ImN6VmJjNGhiR0YxNDF6cEoydFwvNWpnd05VdDBLeVA1RVlBMHpPc0U0aTFBNkc3dTdYQWdQaTRQVjhiZmVJZHBnIiwibWFjIjoiN2ZlNzQxNmZlOTAwODg2OTRlYzk3ZGFhZTEyZGIxMjVlZmQyNzU4Nzg2YTNmMGUwMzg1ZjgxN2Q4NDQ5YWQzNiJ9; laravel_session=eyJpdiI6Im5rS01QZDZPZCtwdnhSb3BGdHVYTmc9PSIsInZhbHVlIjoibHB5SjJNemlcL1NDOVZyZGlMeDc2SzZNUFJtNHhrZmlJWDVBTTZzN0tMNytxOTFxcWttQk9UWEdHQnVhVDZLYW8iLCJtYWMiOiI2ODE1NTM2MjM4YWZiODc4YTU3ZDZlYzcwNjI4OGJlODM3Y2JmNjFjNmFiZmE1YzdmZDk2NmRmZmUwMjg2YzhkIn0%3D; Hm_lpvt_d09fdf7e91f77cddf85908f081d4a3bc=1591613912',
'User-Agent':ua.random,
}
url="http://www.zaixianai.cn/Api_getVoice"
data={
'content': text,
'volume': '50',
'speech_rate': '0',
'voice': 'Aixia',
'_token': 'WyKWhA1OtAf6DIyWN1htvYq6osD8B0qP3gHsRNvq',
}
html=requests.post(url,data=data,headers=headers)
time.sleep(1)
print(html.status_code)
req=html.content.decode('utf-8')
print(req)
mp3=re.findall(r'"file_name":"(.+?)",',req,re.S)[0]
mp3_url=f'http://www.zaixianai.cn/voice/{mp3}'
print(f'>>>获取语音文件成功:{mp3_url}')
get_mp3(mp3_url, mp3)
def get_mp3(mp3_url,mp3):
ua = UserAgent()
r=requests.get(mp3_url,headers={'User-Agent':ua.random})
time.sleep(1)
with open(mp3,'wb') as f:
f.write(r.content)
print(f">>>下载{mp3}成功了!")
if __name__=='__main__':
text=input("请输入要转换为语音的文本内容:")
ai(text)
以上仅供参考和学习!
欢迎关注
交流python