from urllib import parse
import requests
china = input("输入查询的中文")
count = len(china)
url = "https://fanyi.baidu.com/gettts?lan=zh&text="+parse.quote(china)+"&spd=5&source=web"
content = requests.get(url, stream=True)
print(content)
f = open("file_path.mp3", "wb")
# 将内容response 通过该方法 iter_content 把数据读出来然后写到一个文件中
for chunk in content.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
f.close()