登录后台
https://platform.minimaxi.com/user-center/basic-information
找到groupID

复制秘钥

再放代码
py
import requests
import json
group_id = ""
api_key = ""
url = f"https://api.minimax.chat/v1/t2a_v2?GroupId={group_id}"
payload = json.dumps({
"model": "speech-01-turbo",
"text": "真正的危险不是计算机开始像人一样思考,而是人开始像计算机一样思考。计算机只是可以帮我们处理一些简单事务。",
"stream": False,
"voice_setting": {
"voice_id": "male-qn-qingse",
"speed": 1,
"vol": 1,
"pitch": 0,
"emotion":"happy"
},
"pronunciation_dict": {
"tone": [
"处理/(chu3)(li3)", "危险/dangerous"
]
},
"audio_setting": {
"sample_rate": 32000,
"bitrate": 128000,
"format": "mp3",
"channel": 1
}
})
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, stream=True, headers=headers, data=payload)
parsed_json = json.loads(response.text)
# 获取audio字段的值
audio_value = bytes.fromhex(parsed_json['data']['audio'])
with open('output.mp3', 'wb') as f:
f.write(audio_value)