我想将以下 http.client 请求代码转换为请求 库表单。
我尝试这样做,但一直在思考 body 和 header 都将在哪里传递requests.post(url, data=None, json=None, **kwargs)
。我需要使用请求库,主要是因为我想让它异步。
headers = {"Content-type": "application/ssml+xml",
"X-Microsoft-OutputFormat": "audio-16khz-128kbitrate-mono-mp3",
"Authorization": "Bearer " + access_token,
"X-Search-AppId": "__ID__",
"X-Search-ClientID": "__ID__",
"User-Agent": "TTSForPython"}
body = "<speak version='1.0' xml:lang='en-us'><voice xml:lang='en-CA' xml:gender='Female' name='Microsoft Server Speech Text to Speech Voice (en-CA, HeatherRUS)'>" + text + "</voice></speak>"
conn = http.client.HTTPSConnection("speech.platform.bing.com")
conn.request("POST", "/synthesize", body, headers)
response = conn.getresponse()
谢谢!!