"""
本示例用于创建语音合成任务,若使用文件作为输入,则需要将<text_file_id>替换为文本文件的file_id,若使用文本作为输入,则设置"text"字段。注意:需要先将密钥信息写入环境变量 `MINIMAX_API_KEY`。
"""
import requests
import json
import os
api_key = os.environ.get("MINIMAX_API_KEY")
url = "https://api.minimaxi.com/v1/t2a_async_v2"
payload = json.dumps({
"model": "speech-2.5-hd-preview",
"text_file_id": <text_file_id>, # file as input
# "text":"微风拂过柔软的草地,清新的芳香伴随着鸟儿的歌唱。", # text as input
"language_boost": "auto",
"voice_setting": {
"voice_id": "audiobook_male_1",
"speed": 1,
"vol": 10,
"pitch": 1
},
"pronunciation_dict": {
"tone": [
"草地/(cao3)(di1)"
]
},
"audio_setting": {
"audio_sample_rate": 32000,
"bitrate": 128000,
"format": "mp3",
"channel": 2
},
"voice_modify":{
"pitch":0,
"intensity":0,
"timbre":0,
"sound_effects":"spacious_echo"
}
})
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)