跳转到主要内容
POST
/
audio
/
speech
语音合成接口
curl --request POST \
  --url https://geekai.co/api/v1/audio/speech \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "tts-1",
  "input": "你好, 很高兴见到你!",
  "voice": "alloy",
  "response_format": "mp3",
  "stream_format": "audio",
  "speed": 1,
  "instructions": "<string>",
  "retries": 0
}
'
import requests

url = "https://geekai.co/api/v1/audio/speech"

payload = {
"model": "tts-1",
"input": "你好, 很高兴见到你!",
"voice": "alloy",
"response_format": "mp3",
"stream_format": "audio",
"speed": 1,
"instructions": "<string>",
"retries": 0
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'tts-1',
input: '你好, 很高兴见到你!',
voice: 'alloy',
response_format: 'mp3',
stream_format: 'audio',
speed: 1,
instructions: '<string>',
retries: 0
})
};

fetch('https://geekai.co/api/v1/audio/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://geekai.co/api/v1/audio/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'tts-1',
'input' => '你好, 很高兴见到你!',
'voice' => 'alloy',
'response_format' => 'mp3',
'stream_format' => 'audio',
'speed' => 1,
'instructions' => '<string>',
'retries' => 0
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://geekai.co/api/v1/audio/speech"

payload := strings.NewReader("{\n \"model\": \"tts-1\",\n \"input\": \"你好, 很高兴见到你!\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"stream_format\": \"audio\",\n \"speed\": 1,\n \"instructions\": \"<string>\",\n \"retries\": 0\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://geekai.co/api/v1/audio/speech")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"tts-1\",\n \"input\": \"你好, 很高兴见到你!\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"stream_format\": \"audio\",\n \"speed\": 1,\n \"instructions\": \"<string>\",\n \"retries\": 0\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://geekai.co/api/v1/audio/speech")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"tts-1\",\n \"input\": \"你好, 很高兴见到你!\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"stream_format\": \"audio\",\n \"speed\": 1,\n \"instructions\": \"<string>\",\n \"retries\": 0\n}"

response = http.request(request)
puts response.read_body
"<string>"
{
"code": "validation_error",
"message": "参数验证失败",
"details": {
"field": "错误描述"
}
}
{
"code": "unauthorized",
"message": "Invalid API key or token"
}
{
"code": "invalid_request",
"message": "请求参数不合法"
}
{
"code": "invalid_request",
"message": "请求参数不合法"
}
注:语音模型名称设置参考系统支持语音模型列表,请求/响应参数结构完全兼容 OpenAI,切换模型时只需修改对应的模型名称即可,若模型请求/响应参数和OpenAI不一致,极客智坊底层会自动转换对齐。
响应数据格式和 OpenAI 完全兼容,即返回音频文件的二进制数据。 关于文本转语音 API 调用示例,可以参考这里:文本对话

请求/响应参数明细

授权

Authorization
string
header
必填

API认证token

请求体

application/json
model
string
必填

语音模型

示例:

"tts-1"

input
string
必填

需要转换的文本内容

示例:

"你好, 很高兴见到你!"

voice
string

声音角色,不同平台支持的声音角色可能不一样,更多细节请查看文本转语音示例

示例:

"alloy"

response_format
string
默认值:mp3

音频格式,不同平台支持格式可能不一样,更多细节请查看文本转语音示例

stream_format
enum<string>
默认值:audio

语音输出格式,支持 sse/audio 两种格式,sse表示流式输出,audio表示输出音频文件,默认为audio

可用选项:
sse,
audio
speed
enum<number>
默认值:1

语速,取值范围[0.25, 1.0, 4.0],默认1.0,其中豆包语音模型仅支持[0.5, 1, 2]三个档位

可用选项:
0.25,
0.5,
1,
2,
4
instructions
string

使用额外指令来控制生成的音频音调,仅 gpt-4o-mini-tts 模型支持该参数

retries
integer
默认值:0

自动重试次数,默认0,表示失败不重试

响应

成功响应

MP3格式音频