curl --request POST \
--url 'https://api.elkapi.com/v1/audio/speech' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
}'
import requests
url = "https://api.elkapi.com/v1/audio/speech"
headers = {
"Authorization": "Bearer <token>"
}
headers["Content-Type"] = "application/json"
payload = {
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.json())
const url = "https://api.elkapi.com/v1/audio/speech";
const headers = {
"Authorization": "Bearer <token>"
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
};
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(payload)
});
console.log(await response.json());
"string"
原生 OpenAI 格式
文本转语音
- 将文本转换为音频
POST
/
v1
/
audio
/
speech
curl --request POST \
--url 'https://api.elkapi.com/v1/audio/speech' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
}'
import requests
url = "https://api.elkapi.com/v1/audio/speech"
headers = {
"Authorization": "Bearer <token>"
}
headers["Content-Type"] = "application/json"
payload = {
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.json())
const url = "https://api.elkapi.com/v1/audio/speech";
const headers = {
"Authorization": "Bearer <token>"
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
};
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(payload)
});
console.log(await response.json());
"string"
curl --request POST \
--url 'https://api.elkapi.com/v1/audio/speech' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
}'
import requests
url = "https://api.elkapi.com/v1/audio/speech"
headers = {
"Authorization": "Bearer <token>"
}
headers["Content-Type"] = "application/json"
payload = {
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.json())
const url = "https://api.elkapi.com/v1/audio/speech";
const headers = {
"Authorization": "Bearer <token>"
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "tts-1",
"input": "今天天气真好,适合出去散步。",
"voice": "alloy",
"response_format": "mp3"
};
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(payload)
});
console.log(await response.json());
"string"
Authorizations
string
必填
所有接口均需要使用 Bearer Token 进行认证。在请求头中添加:
Authorization: Bearer YOUR_API_KEY
Body
string
默认值:"tts-1"
必填
示例:
tts-1string
必填
要转换的文本
string
必填
可选值:
alloy、echo、fable、onyx、nova、shimmerstring
默认值:"mp3"
可选值:
mp3、opus、aac、flac、wav、pcmnumber
默认值:"1"
⌘I