音频
文字转语音
将文本转换为语音音频(返回 MP3 二进制数据)。
POST
/
api
/
v1
/
audio
/
tts
文字转语音
curl --request POST \
--url https://api.example.com/api/v1/audio/tts \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"voice": "<string>",
"speed": 123
}
'import requests
url = "https://api.example.com/api/v1/audio/tts"
payload = {
"text": "<string>",
"voice": "<string>",
"speed": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: '<string>', voice: '<string>', speed: 123})
};
fetch('https://api.example.com/api/v1/audio/tts', 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://api.example.com/api/v1/audio/tts",
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([
'text' => '<string>',
'voice' => '<string>',
'speed' => 123
]),
CURLOPT_HTTPHEADER => [
"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://api.example.com/api/v1/audio/tts"
payload := strings.NewReader("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
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://api.example.com/api/v1/audio/tts")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/audio/tts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}"
response = http.request(request)
puts response.read_body将文本转换为语音。返回的是原始音频字节(
audio/mpeg),而不是 JSON。
响应内容是一个二进制 MP3 文件,而不是 JSON 对象。
Content-Type 响应头为 audio/mpeg。身份验证
需要提供 Bearer 令牌。详见身份验证。请求体
string
必填
要转换为语音的文本。最多 4,096 个字符。
string
默认值:"theo-voice-classic"
可选的 Theo 语音标识符。省略则使用默认语音。未知的取值会回退到
theo-voice-classic。| 语音 | 特点 |
|---|---|
theo-voice-classic | 中性、多用途——默认音色 |
theo-voice-bright | 明亮、清晰、活泼 |
theo-voice-storyteller | 叙事感强、富有表现力 |
theo-voice-deep | 低沉、权威 |
theo-voice-warm | 温暖、专业 |
theo-voice-soft | 柔和、沉稳 |
number
默认值:"1.0"
播放速度倍率(0.25–4.0)。
请求示例
curl -X POST https://www.hitheo.ai/api/v1/audio/tts \
-H "Authorization: Bearer $THEO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Welcome to Theo. How can I help you today?",
"voice": "theo-voice-warm",
"speed": 1.0
}' \
--output speech.mp3
const audioBuffer = await theo.tts({
text: "Welcome to Theo. How can I help you today?",
voice: "theo-voice-warm",
speed: 1.0,
});
// audioBuffer is an ArrayBuffer — write to file or stream to client
import { writeFileSync } from "fs";
writeFileSync("output.mp3", Buffer.from(audioBuffer));
响应
响应体是原始 MP3 音频字节。| 响应头 | 值 |
|---|---|
Content-Type | audio/mpeg |
Content-Length | 文件大小(字节数) |
X-Request-Id | 唯一请求 ID(前缀为 tts_) |
错误
| 状态码 | 错误码 | 说明 |
|---|---|---|
| 400 | missing_text | 缺少必填的 text 参数 |
| 401 | invalid_api_key | API 密钥缺失或无效 |
| 502 | tts_provider_error | Theo 语音引擎返回错误——请重试 |
| 503 | tts_unavailable | 此实例未配置文字转语音功能 |
此页面对您有帮助吗?
文字转语音
curl --request POST \
--url https://api.example.com/api/v1/audio/tts \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"voice": "<string>",
"speed": 123
}
'import requests
url = "https://api.example.com/api/v1/audio/tts"
payload = {
"text": "<string>",
"voice": "<string>",
"speed": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: '<string>', voice: '<string>', speed: 123})
};
fetch('https://api.example.com/api/v1/audio/tts', 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://api.example.com/api/v1/audio/tts",
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([
'text' => '<string>',
'voice' => '<string>',
'speed' => 123
]),
CURLOPT_HTTPHEADER => [
"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://api.example.com/api/v1/audio/tts"
payload := strings.NewReader("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
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://api.example.com/api/v1/audio/tts")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/audio/tts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}"
response = http.request(request)
puts response.read_body