请求method:POST
请求头:Authorization:Bearer YOUR_ACCESS_TOKEN
这个ACCESS_TOKEN可以在:https://chatgpt.com/api/auth/session 这个地址拿到
请求体:
{
"model": "tts-1",
"input": "那个天才的想法这就实现了?你真特么是个天才!",
"voice": "shimmer",
"response format": "aac"
}
python代码是从评论区一个大佬抄过来的
from openai import OpenAI
key = "从https://chat.openai.com/api/auth/session获取的"
base_url = "https://api.oaifree.com/v1"
# 从文件中读取文本
with open('input_text.txt', 'r', encoding='utf-8') as file:
input_text = file.read()
# 初始化客户端
client = OpenAI(
api_key=key,
base_url=base_url
)
# 调用语音合成API,使用读取的文本作为输入
response = client.audio.speech.create(
model="tts-1",
voice="onyx",
input=input_text
)
# 假设response对象有一个方法来获取二进制内容,如.content
# 这将直接取决于OpenAI客户端库的实现
# 以下是如何将响应内容保存到文件的示例
with open("output.mp3", "wb") as file:
file.write(response.content)
input_text.txt是源文本
output.mp3输出文件